Skip to content
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

Do not throw an InvalidProjectFileException if ProjectLoadSettings.IgnoreMissingImports is specified #2991

Merged
merged 2 commits into from
Feb 14, 2018

Conversation

jeffkl
Copy link
Contributor

@jeffkl jeffkl commented Feb 13, 2018

InvalidProjectFileExceptions cause modal dialogs in Visual Studio which so we should respect ProjectLoadSettings.

Related to dotnet/project-system#3240

@jeffkl jeffkl changed the base branch from master to vs15.6 February 13, 2018 23:39
@jeffkl jeffkl added this to the MSBuild 15.6 milestone Feb 13, 2018
@jeffkl
Copy link
Contributor Author

jeffkl commented Feb 13, 2018

fyi @jviau

@jeffkl
Copy link
Contributor Author

jeffkl commented Feb 13, 2018

Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

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

LGTM but I'm not sure this corner case warrants a fix this late. See what shiproom says.


_evaluationLoggingContext.LogBuildEvent(eventArgs);

projects = new List<ProjectRootElement>();
Copy link
Member

Choose a reason for hiding this comment

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

This line confuses me, but seems correct from context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, projects is an out parameter so it must be set before returning...

BuildEventContext = _evaluationLoggingContext.BuildEventContext,
UnexpandedProject = importElement.Project,
ProjectFile = importElement.ContainingProject.FullPath,
ImportedProjectFile = null,
Copy link

@jviau jviau Feb 13, 2018

Choose a reason for hiding this comment

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

Currently I use ImportedProjectFile to track imports that were ignored, so I can attempt reloads as they change (in case they become valid). Can we get 2 separate events, one for sdk.props and one for sdk.targets?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The event will be logged twice but since no project was imported then ImportedProjectFile is null. UnexandedProject is Sdk.props and Sdk.targets. Will that work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tehavior we saw when trying things out was that Visual Studio unloads a project and when you try to reload it you get an error. An SDK not found with IgnoreMissingImports would evaluate to this:

<Project>
  
  <PropertyGroup>
    <TargetFramework>netstandard1.3</TargetFramework>
  </PropertyGroup>

</Project>

And you get this when you save it, VS unloads it, and you try to reload it.

image

Are you saying you would leave the project loaded and then attempt to reload it if the user fixed it?

Copy link

@jviau jviau Feb 14, 2018

Choose a reason for hiding this comment

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

When I added IgnoreInvalidImport I refined the contract for ImportedProjectFile. It should only be null if the condition is false or it is a glob with no matches. This is a case I didn't consider - import is ignored, but the full path is still unknown (because any resolver could eventually supply it). I will have to make a change to CPS to handle this.

Unless you want to set the full path as what the default SDK resolver would supply - the SDK directory under msbuild. Not sure if that is the correct behavior though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The default SDK resolver only returns the path if it exists so the Evaluator would not know the value. The only options are:

  1. Use the value in the Project attribute, Sdk.props and Sdk.targets
  2. Use null since a path could not be determined

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe there's a difference between a "core" SDK like m.net.sdk(.web) and a custom one not being resolved? As long as you don't mess around with that core sdk and only have a broken reference to a NuGet one, does it still show that error dialog?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dasMulli correct, if another non "core" SDK is invalid and ignored, you will not get a dialog. You still get a build error which is what we want but VS does not unload the project

Copy link

@jviau jviau Feb 14, 2018

Choose a reason for hiding this comment

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

I am not sure CPS will be able to tell if a "core" SDK (or really any SDK) has broken at the time of reload. It is far too expensive to re-evaluate the project during the reload. Comparing if any Sdk elements or attributes changed won't be enough either, as they can be evaluated - ie: <Sdk Name="$(MySdk)" Version="$(SdkVersion)" />

Letting the error dialog @jeffkl showed above display isn't ideal either, as it would be 1 per project. So if an Sdk came from a shared import, you would see multiple dialogs show up.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this now meets the bar for 15.6 since we will have to make a considerable change to CPS as well.

The experience when breaking the core SDK isn't very good in 15.5 either, but this fix would help a lot when tinkering with custom SDKs, which is a feature in 15.6 that encourages users to modify SDK imports. If some form of a fix that doesn't make me click through hundreds (=6 ^^) of dialogs when I break something in the custom import (or on the NuGet feed) makes it into 15.6.*, that would be awesome!!

For reference, this happens when I break the core SDK in 15.5 (after which the project is just unloaded):

screen shot 2018-02-14 at 19 45 26

screen shot 2018-02-14 at 19 44 49

Copy link

@jviau jviau Feb 14, 2018

Choose a reason for hiding this comment

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

I agree that experience is awful. To get a good experience we need to do a lot of validation of what has changed in the project during a reload, so that we never reload into a broken "core" SDK. This is very expensive to do, especially when a common import is changed (we have to validate every project that imports it). I am thinking we will have to do something like track every property that is impacting the final SDK result, and if any of them change, we submit an error to the error list asking the user to eventually reload the solution.

@jeffkl
Copy link
Contributor Author

jeffkl commented Feb 14, 2018

Hmm Jenkins seems to be using the netci.groovy from master instead of my branch so the build on Mac is failing.

@rainersigwald
Copy link
Member

I don't understand why it's running both flavors of macOS CI job. But since the correct one passed I'm ok with moving forward (pending shiproom approval).

@AndyGerlicher AndyGerlicher merged commit 7377aec into dotnet:vs15.6 Feb 14, 2018
@jeffkl jeffkl deleted the ignoresdk branch February 14, 2018 21:34
@jviau
Copy link

jviau commented Feb 14, 2018

When is this going to be inserted to 15.6? CPS will need changes as well, the null is going to cause us to throw with our current code.

@jeffkl
Copy link
Contributor Author

jeffkl commented Feb 14, 2018

@AndyGerlicher was working on an insertion today

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.

None yet

5 participants