Error NETSDK1061 encountered when run "dotnet publish"

Song Xu (NCS) 0 Reputation points
2024-09-30T07:12:41.6933333+00:00

Hi All,

Good afternoon.

Let me first give a big picture on my project. The main project is using .NET8.0, and it has 2 dependencies. One of the dependencies is using netcoreapp2.1, which is also the one trigger the error NETSDK1061.

 

I encountered a error when trying to publish the project using following command: "dotnet publish xxxxxxx.csproj -c Release -f net8.0 -o output_file_path -r win-x64 --self-contained true"

The error is as attached:User's image

Both version 2.1.30 and 2.1.0 is not specified explicitly in our project file. (We only include <TargetFramework>netcoreapp2.1</TargetFramework> in the dependency's csproj file)

 

Similar problem did not occur before when the main project is using .NET6. (the dependency's framework version is still 2.1 at that time.)

 

How we resolve this:

 

I spill the command "dotnet publish xxxxxxx.csproj -c Release -f net8.0 -o output_file_path -r win-x64 --self-contained true" into 2 steps of command:

Step1, "dotnet restore xxxxxx.sln (or xxxxx.csproj) -r win-x64"

Step2, "dotnet publish xxxxxxx.csproj -c Release -f net8.0 -o output_file_path -r win-x64 --self-contained true --no-restore"

 

And then it will publish successfully. But we do not know the root cause of this problem, especially:

1, why the error only occurred when the main project is using .NET8, while before in .NET6 it did not occur?

2, why doing "dotnet restore" manually will solve this error in .NET8?

 

I also notice that specifying either of the 2 field in the dependency's csproj file can resolve this error as well (but the reason is also not clear):

<!--<RuntimeFrameworkVersion>2.1.0</RuntimeFrameworkVersion>-->
<!--<RuntimeIdentifier>win-x64</RuntimeIdentifier>-->

 

 

Hope to hear from you soon.

Many thanks.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,905 questions
.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
337 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,166 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jack J Jun 24,516 Reputation points Microsoft Vendor
    2024-10-01T07:11:22.03+00:00

    @Song Xu (NCS) ,Welcome to Microsoft Q&A, based on my test, I indeed reproduced your problem about your NETSDK1061 error.

    why the error only occurred when the main project is using .NET8, while before in .NET6 it did not occur?

    Because .NET 8.0 projects are no longer compatible with .NET Core 2.1 libraries. While .NET 6.0 still supports .NET Core 2.1, .NET 8.0 has removed support for older versions, so you'll encounter version-conflict errors when publishing. And based on my test, if I upgrade .NET Core2.1 to .net 6.0, the error will not occur again.

    why doing "dotnet restore" manually will solve this error in .NET8

    dotnet restore solves this problem because it ensures that the correct version is downloaded and used by restoring the project's dependencies and tools. Specifically, it resolves version mismatches between projects and libraries.

    Hope it could you understand the question.

    Best Regards,

    Jack


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.