Skip to content

Fallback on failed global.json SDK resolution in VS#12633

Merged
sfoslund merged 6 commits into
dotnet:masterfrom
sfoslund:SdkGlobalJsonResolution
Aug 6, 2020
Merged

Fallback on failed global.json SDK resolution in VS#12633
sfoslund merged 6 commits into
dotnet:masterfrom
sfoslund:SdkGlobalJsonResolution

Conversation

@sfoslund
Copy link
Copy Markdown
Member

Fixes #11238

Tested manually in VS:
GlobalJsonSDKResolution

Comment thread src/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs Outdated
Comment thread src/Microsoft.DotNet.MSBuildSdkResolver/NETCoreSdkResolver.cs Outdated
Comment thread src/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs Outdated
Comment thread src/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs Outdated
@wli3
Copy link
Copy Markdown

wli3 commented Jul 30, 2020

Looks good so far. Any reason it is still in draft?

@sfoslund
Copy link
Copy Markdown
Member Author

Any reason it is still in draft?

@wli3 I'm waiting until my MSBuild change (dotnet/msbuild#5562) flows here before I take it out of draft.

@sfoslund sfoslund marked this pull request as ready for review August 3, 2020 19:38
@sfoslund sfoslund requested review from dsplaisted and wli3 August 3, 2020 19:38
Copy link
Copy Markdown
Member

@dsplaisted dsplaisted left a comment

Choose a reason for hiding this comment

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

Looks like there are some resources conflicts you'll need to resolver.

Comment thread src/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs Outdated
Comment thread src/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs Outdated
Comment thread src/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs Outdated
Comment thread src/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs
</Target>

<Target Name="_CheckForFailedSDKResolution"
BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this target run during design-time build? I think not, but can you make sure we don't prevent resolving framework references and NuGet packages so there's a decent intellisense experience.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't have a good understanding of design time builds, so I don't know. Right now this target runs before resolving framework references and packages in the build, does that interfere with intellisense? Should I hook it in later in the build?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are targets which gather the references to pass to the compiler for intellisense and other tooling. We don't want to prevent those targets from running successfully.

I think that this target probably isn't run for the design time build, but check to make sure that when the global.json resolution fails, that in VS you can add a PackageReference and get Intellisense for APIs from the package as well as from .NET Core.

If the target is run, then we can avoid the check in design time builds, something like this:

<!-- For design-time builds, don't generate an error if a targeting pack isn't available (ie because it hasn't been restored yet) -->
<PropertyGroup Condition="'$(GenerateErrorForMissingTargetingPacks)' == ''">
<GenerateErrorForMissingTargetingPacks>true</GenerateErrorForMissingTargetingPacks>
<GenerateErrorForMissingTargetingPacks Condition="'$(DesignTimeBuild)' == 'true'">false</GenerateErrorForMissingTargetingPacks>
</PropertyGroup>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I see, I did some manual testing and I was able to add a package and get intellisense for the package APIs, so we should be good here.

Comment on lines +29 to +30
testProject.AdditionalProperties["SdkResolverHonoredGlobalJson"] = "false";
testProject.AdditionalProperties["SdkResolverGlobalJsonPath"] = fakePath;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of creating these properties specifically, could you create a global.json pointing to an invalid version? Then you could also have to variants of the test, one with BuildingInsideVisualStudio true, and one false, and test the different behaviors.

This would be a full framework only test, since the resolver isn't used for .NET Core MSBuild. And I'm not sure if we hook up the SDKResolver for full framework tests or not, so it might not easily be possible. But if the SDKResolver already is hooked up, I'd go ahead and try to make the change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It doesn't seem like the SDK resolver it hooked up, I haven't been able to write this type of test.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Now I'm remembering more. There's not a good test hook for adding an SDK resolver. That prevents us from testing the MSBuild SDK resolver in end-to-end scenarios, and will also prevent us from testing the workload resolver on full framework.

I think as a follow-up, we should try to add a test hook in MSBuild for this. IE when looking for SDK resolvers, if an MSBUILDADDITIONALSDKRESOLVERSFOLDER environment variable is specified, then we should look there for SDK resolvers in addition to the SdkResolvers folder in the MSBuild bin directory. If there are folder names with the same name in both paths, the one from the test hook should override the built-in one (so we can test changes to a resolver that ships in MSBuild).

Could you file an MSBuild issue to add the test hook, and and SDK issue to add end-to-end tests for the global.json resolution once that's done?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That makes sense, I've filed dotnet/msbuild#5618 and #12810. I'll keep these in my backlog of work, I should be able to get to them in the next few weeks.

@dsplaisted
Copy link
Copy Markdown
Member

Looks good to merge 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When global.json specifies an SDK that can't be found, don't block project load in Visual Studio

3 participants