-
Notifications
You must be signed in to change notification settings - Fork 1.1k
net 6.0 throws NETSDK1005 error during publish as it does not accept the property "TargetFramework" #19487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The workaround works because you are setting TargetFramework in your original csproj file to match what you have. If you have
or,
both of these would not work. If you want to target multiple frameworks, you would have
Make sure that you have TargetFrameworks (Plural) tag. |
Ryan has the accurate summary here (thanks @ryank425 ). To add to this, MSBuild properties that are set by environment variables or CLI will get overwritten if you set them in your project file because MSBuild does an initial pass over all properties and whatever value is set last wins. That's why you'll find all throughout MSBuild and the SDK checks to see if a value is already set before overwriting it. Something like the below might work as well as it won't overwrite the value you set on the command line and will set it if it's not set.
|
That's not consistent with Global properties, which says the -property switch overrides values that would be set in the project file. |
@marcpopMSFT, it doesn't work as expected, documented or as it worked before.
If we try to compile it using SDK 5.4.0 with command: Really, as @KalleOlaviNiemitalo mentioned, /p switch should take precedence over content of project file, unless property is ii "TreatAsLocalProperty" attribute of "Project" element - and it works as documented, based on "Test" target output. Even more - adding |
It's possible I misunderstood the original issue as reading it again, they say that the build failed. I assumed they meant that the TFM was not being set correctly but with the latest comment, it sounds like the /p switch is working correctly but rather that's triggering NETSDK1005. @dsplaisted, this appears to be a change in behavior between 5.0 and 6.0 that 6.0 will give the NETSDK1005 if you don't restore first but net5.0 won't. Checking the binlogs, looks like the error shows up before the restore Target has run so there may be an ordering change in 6.0 that we need to resolve here. |
The behavior for the .NET 6 SDK is the behavior we intended. I'm not sure why the .NET 5.0 SDK isn't behaving the same way, looking at the code makes it look like it should do the same thing. I'm guessing there was a bug that was fixed as part of the process of changing the command line parser to System.CommandLine for the .NET 6.0 SDK. The reason this is the intended behavior is for the scenario where you have multiple TargetFrameworks defined in the project file, and you want to build one of them. In that case, we want to avoid invalidating the NuGet restore operation, so we exclude the TargetFramework property from being passed to Restore. However, that design doesn't work for people who want to pass in a TargetFramework which is not listed in the project's To correctly handle both cases, we would need to evaluate the project, and see if the The logic lives here: https://github.com/dotnet/sdk/blob/main/src/Cli/dotnet/commands/RestoringCommand.cs |
Here's some context from a few years back to explain why the implicit restore isn't set up in this situation: Sounds like customers can do a separate restore or add /restore to workaround this. Not sure reading the project for the existing TFM and trying to change the behavior based on that is a high enough priority at the moment. |
@marcpopMSFT, separate call of |
Made pass over A-M letters in project. Had to fix a test to workaround bug #19487
Below command fails with net 6.0,
dotnet publish "MY_TEST_APP_CSPROJ_PATH" -c Release -o "RELEASE_PROJ_PATH" -r win10-x64 /p:TargetFramework=net6.0
As a workaround, I updated csproj to accept the variable (TF)
<TargetFramework>$(TF)</TargetFramework>
and running the below command works,
dotnet publish "MY_TEST_APP_CSPROJ_PATH" -c Release -o "RELEASE_PROJ_PATH" -r win10-x64 /p:TF=net6.0
The text was updated successfully, but these errors were encountered: