-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Report better error when Microsoft.Net.Sdk.Compilers.Toolset
package is not downloaded
#42216
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
Conversation
…e is not downloaded
@@ -952,5 +952,9 @@ You may need to build the project on another operating system or architecture, o | |||
<value>NETSDK1215: Targeting .NET Standard prior to 2.0 is no longer recommended. See {0} for more details.</value> | |||
<comment>{StrBegin="NETSDK1215: "}</comment> | |||
</data> | |||
<!-- The latest message added is TargetFrameworkIsNotRecommended. Please update this value with each PR to catch parallel PRs both adding a new message --> | |||
<data name="MicrosoftNetSdkCompilersToolsetNotFound" xml:space="preserve"> | |||
<value>NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded. Either run NuGet package restore or set property 'BuildWithNetFrameworkHostedCompiler' to 'false' to force use of the compiler bundled with MSBuild.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to change the wording of this a bit but am having trouble getting it just right. The current message says what is wrong (the package wasn't downloaded) and how to fix it (restore or toggle the flag), but it doesn't say why the problem is a problem. I want something like
NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is was not downloaded but was inferred to be required based on the current build environment. Either run NuGet package restore or set property 'BuildWithNetFrameworkHostedCompiler' to 'false' to force use of the compiler bundled with MSBuild.
But that's not much better :-/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
property 'BuildWithNetFrameworkHostedCompiler' to 'false' to force use of the compiler bundled with MSBuild
I'm concerned about this recommendation. Once this error is hit the product is essentially in a broken state (cannot find vital components of the product). Flipping in this property is essentially silencing that signal that something is wrong. It then leads customers into the bad behaviors we saw before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once this error is hit the product is essentially in a broken state (cannot find vital components of the product)
I'm not sure that's correct, you can simply be using some internal company feed instead of the public nuget.org. In normal console apps etc that used to be completely fine. Or build in VS/MSBuild after restoring via dotnet CLI.
Flipping in this property is essentially silencing that signal that something is wrong. It then leads customers into the bad behaviors we saw before.
Sure but don't we want to tell customers how to suppress this error so they can unblock themselves - given the error is effectively a breaking change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps something like:
NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure it is available in your NuGet feeds and then run NuGet package restore from Visual Studio or MSBuild.
Customers wanting a workaround can find it in the package's docs (#42212).
I've also tried to emphasize that you should restore via msbuild because dotnet restore
wouldn't work.
Maybe dotnet restore /p:BuildWithNetFrameworkHostedCompiler=true
would work and we can add that to the package docs.
What are the ways that we expect that this error could be generated? Is it just when you run build while skipping restore? Understanding that may help write a better error message. |
Offline we figured out that it's "restore with |
Actually, that would work - Visual Studio runs its own restore on start. But if you for example removed the package after VS did its restore, then VS would not detect the package is missing and proceed to build, now falling back to the mismatched compiler version because the UsingTask was made conditional (#42238). There are some other scenarios where this error could be useful like |
<Target Name="_CheckMicrosoftNetSdkCompilersToolsetPackageExists" Condition="'$(_NeedToDownloadMicrosoftNetSdkCompilersToolsetPackage)' == 'true'" BeforeTargets="CoreCompile"> | ||
<!-- If users did not run restore or it failed to download the Microsoft.Net.Sdk.Compilers.Toolset package | ||
(but they proceeded to build, e.g., in Visual Studio), display an error with suggestions how to fix the problem. --> | ||
<NETSdkError ResourceName="MicrosoftNetSdkCompilersToolsetNotFound" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could also be just a warning since technically the build will fall back to the compiler bundled with MSBuild - I don't know if that's a scenario we want to error or warn about. I chose error because that can be always relaxed without breaking users unlike the other way around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose error because that can be always relaxed without breaking users unlike the other way around.
I endorse this philosophy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I worry about breaking users, perhaps a warning would be better (it could be suppressed). @jaredpar also mentioned this should be a warning right?
@@ -952,5 +952,9 @@ You may need to build the project on another operating system or architecture, o | |||
<value>NETSDK1215: Targeting .NET Standard prior to 2.0 is no longer recommended. See {0} for more details.</value> | |||
<comment>{StrBegin="NETSDK1215: "}</comment> | |||
</data> | |||
<!-- The latest message added is TargetFrameworkIsNotRecommended. Please update this value with each PR to catch parallel PRs both adding a new message --> | |||
<data name="MicrosoftNetSdkCompilersToolsetNotFound" xml:space="preserve"> | |||
<value>NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know the version available at this point? It would be more helpful to tell the user "you need version X of package Y" than just "you need package Y".
<value>NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild.</value> | |
<value>NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure version {0} of the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild.</value> |
Note that this will require updating the callsite with formatting arguments.
<!-- The latest message added is TargetFrameworkIsNotRecommended. Please update this value with each PR to catch parallel PRs both adding a new message --> | ||
<data name="MicrosoftNetSdkCompilersToolsetNotFound" xml:space="preserve"> | ||
<value>NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild.</value> | ||
<comment>{StrBegin="NETSDK1216: "}{Locked="Microsoft.Net.Sdk.Compilers.Toolset"}</comment> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<comment>{StrBegin="NETSDK1216: "}{Locked="Microsoft.Net.Sdk.Compilers.Toolset"}</comment> | |
<comment>{StrBegin="NETSDK1216: "}{Locked="Microsoft.Net.Sdk.Compilers.Toolset"} {0} is a NuGet package version and should not be translated. </comment> |
/backport to release/9.0.1xx-preview7 |
Started backporting to release/9.0.1xx-preview7: https://github.com/dotnet/sdk/actions/runs/10075584748 |
@jjonescz an error occurred while backporting to release/9.0.1xx-preview7, please check the run log for details! Error: @jjonescz is not a repo collaborator, backporting is not allowed. If you're a collaborator please make sure your dotnet team membership visibility is set to Public on https://github.com/orgs/dotnet/people?query=jjonescz |
Related to #41791 and https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2136930.