Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 3 commits into from
Jul 24, 2024

Conversation

jjonescz
Copy link
Member

@ghost ghost added Area-Infrastructure untriaged Request triage from a team member labels Jul 17, 2024
@jjonescz jjonescz marked this pull request as ready for review July 17, 2024 14:12
@@ -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>
Copy link
Member

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 :-/

Copy link
Member

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.

Copy link
Member Author

@jjonescz jjonescz Jul 18, 2024

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?

Copy link
Member Author

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.

@dsplaisted
Copy link
Member

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.

@rainersigwald
Copy link
Member

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 dotnet restore or one of the things that do it implicitly, then load the project in VS and attempt to build without triggering restore first".

@jjonescz
Copy link
Member Author

jjonescz commented Jul 19, 2024

Offline we figured out that it's "restore with dotnet restore or one of the things that do it implicitly, then load the project in VS and attempt to build without triggering restore first".

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 dotnet restore && msbuild -t:Build I guess.

<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"
Copy link
Member Author

@jjonescz jjonescz Jul 19, 2024

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.

Copy link
Member

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.

Copy link
Member Author

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>
Copy link
Member

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".

Suggested change
<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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<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>

@jjonescz jjonescz merged commit 2a0c0f0 into dotnet:main Jul 24, 2024
37 checks passed
@jjonescz jjonescz deleted the tearing-error branch July 24, 2024 08:03
@jjonescz
Copy link
Member Author

/backport to release/9.0.1xx-preview7

Copy link
Contributor

Started backporting to release/9.0.1xx-preview7: https://github.com/dotnet/sdk/actions/runs/10075584748

Copy link
Contributor

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Infrastructure untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants