dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.93k stars 4.02k forks source link

Need to enable Use Preview Sdks in order to build Roslyn from command line #34927

Open KirillOsenkov opened 5 years ago

KirillOsenkov commented 5 years ago

Open Visual Studio 2019, Tools -> Options -> Projects and Solutions -> .NET Core and uncheck Use Previews of the .NET Core SDKs:

image

(in 8.1 this will be in Tools -> Options -> Environment -> Preview Features)

Then git clone https://github.com/dotnet/roslyn and run build.cmd -restore. It will fail with "Unable to find .NET Core SDK".

The checkbox to allow prerelease SDKs actually sets the contents of %localappdata%\Microsoft\VisualStudio\16.0_1b19bc0d\sdk.txt settings file to either: UsePreviews=true or UsePreviews=false. (The 1b19bc0d part of the file path is your Visual Studio installation instance Id).

This code in the .NET Core SDK Resolver reads this flag: https://github.com/dotnet/cli/blob/bfffcb23ba270640b355e729f36b34c04fad0121/src/Microsoft.DotNet.MSBuildSdkResolver/VSSettings.cs#L55-L60

Setting that checkbox is a prerequisite for building Roslyn and it is incredibly hard to figure out why Roslyn failed to build from the symptom.

We should either print a warning, or read that file and print a warning if it's not found or is set to false. Or maybe just write the file as part of installing the 3.0 SDK. The difficulty is in finding the VS instance id, but vswhere can provide that.

jmarolf commented 5 years ago

@jaredpar @tmat isn't arcade supposed to install its own CLI from the commandline? I thought this would only happen in you built from within VS?

jaredpar commented 5 years ago

@jmarolf

Yes / no. Up until now we've had no way to know if this setting was or was not set. I asked before but didn't get a solid answer. Hence we haev no way of knowing if the VS build will or won't work.

jaredpar commented 5 years ago

@KirillOsenkov

Setting that checkbox is a prerequisite for building Roslyn and it is incredibly hard to figure out why Roslyn failed to build from the symptom.

Understood. I've hit the same problem as well. It's not a decision we made though, it's a limitation we have to work with.

The checkbox to allow prerelease SDKs actually sets the contents of %localappdata%\Microsoft\VisualStudio\16.0_1b19bc0d\sdk.txt settings file to either: UsePreviews=true or UsePreviews=false.

We can try and read that to give an message. But it's more work to figure out the ID we're using (not always obvious) to construct the string for the check.

We should either print a warning

As always I want our build to be simple. But with the SDK it's often outside our control. Have to adapt.

sharwell commented 5 years ago

Agreed, this is a really bad experience today.

@dotnet/msbuild What steps are necessary to force-override the setting in sdk.txt from a command line build?

nguerrera commented 5 years ago

if you put global.json with a 3.0.100-preview sdk version, then VS can load it without the checkbox being set. There are other consequences to global.json though. (Note: roslyn has a global.json, but not the field that actually pins the sdk, only the one that tells arcade which one to acquire.) Pinning is often not what you want, though, you really want a min version. We're adding that to global.json. We are also working out a plan for better diagnostics. It turns out to be harder than expected, but we do agree that this is painful and it is a priority to improve it. Thank you for the feedback.

nguerrera commented 5 years ago

One thing this demonstrated that we have missed in other feedback is the distinction between the failure in the (for lack of a better term) "arcade" case. There you have set a private preview on PATH and DOTNET_MULTILEVEL_LOOKUP=0, so the preview SDK on PATH is the only candidate. In that case, it will be easy to have a better error message and this is a simple bug fix, so we'll do that. The common case where UsePreviews=false finds an RTM SDK (by design), then the error comes from that RTM SDK saying "hey what's this netcoreapp3.0 from the future".

nguerrera commented 5 years ago

In addition to min-version-not-pinning in global.json, we have committed to adding a setting to enable previews in global.json. This would override the checkbox directly for any build of the repo.

tmat commented 5 years ago

In addition to min-version-not-pinning in global.json

Will we be able to use this in Arcade and remove our custom "dotnet" entry? Is there a proposal with syntax?

KirillOsenkov commented 3 years ago

As far as I saw with global.json this no longer seems to be a problem? Shall we close this?

sharwell commented 3 years ago

If this is no longer necessary, we might also need to update the contributor instructions:

https://github.com/dotnet/roslyn/blob/f8107de2a94a01e96ac3d7c1f225acbb61e18830/docs/contributing/Building%2C%20Debugging%2C%20and%20Testing%20on%20Windows.md#L21

KirillOsenkov commented 3 years ago

No I think I was wrong yesterday, this still seems to be required when the restore script wants to build Arcade’s tools.proj which doesn’t have a global.json.