Skip to content

Skip import of Microsoft.NuGet.props and Microsoft.NuGet.targets #870

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 5 commits into from
Feb 16, 2017

Conversation

natidea
Copy link
Contributor

@natidea natidea commented Feb 15, 2017

Fixes dotnet/project-system#1474 and dotnet/project-system#1508

Customer scenario

Customers restoring projects with reference to certain packages (e.g. System.ValueTuple) will see hundreds of downgrade warnings, when they restore from Visual Studio. However they don't see those same warnings when restoring from the CLI.

The root cause is that the VS targets automatically import Microsoft.NuGet.targets, which contains legacy properties and targets associated with project.json. This targets file is specified as an automatic "ImportAfter" Microsoft.Common.targets for all project types. Other errors are sometimes reported because of the inclusion of this file (dotnet/project-system#1508). The downgrade warnings occur because more RIDs are restored than are specified because of this property in Microsoft.NuGet.targets:

<RuntimeIdentifiers>win;win-x86;win-x64</RuntimeIdentifiers>

The CLI dropped this file from their version of ImportAfter, however VS cannot drop it since it is used by other project types. This change adds some conditions allowing us to skip importing this file in .NET Core projects.

There are two parts to this fix:

  • a VS side change which adds conditions to the imports: PR 57278
  • this SDK PR sets the properties for .NET Core projects

Bugs this fixes:

dotnet/project-system#1474 and dotnet/project-system#1508

Risk

Low. The risk may come from us accidentally depending on properties defined in Microsoft.NuGet.targets but all relevant properties have already been copied over to our targets. Furthermore the CLI has been operating without a dependency on this for some time so this ensures parity between the VS and CLI experience.

Performance impact

None

Is this a regression from a previous update?

No

How was the bug found?

Dogfooding

/cc @srivatsn @dsplaisted @nguerrera

@@ -577,5 +577,15 @@ public void It_passes_ridless_target_to_compiler()
.Should()
.Pass();
}

[Fact]
public void It_restores_only_ridless_tfm()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note this test passes even without this fix because it uses dotnet.exe which already excludes Microsoft.NuGet.targets. But this seems like a good scenario to ensure we don't regress.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you'll get coverage from the full msbuild runs in Jenkins.

Copy link
Member

Choose a reason for hiding this comment

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

I think you'll get coverage from the full msbuild runs in Jenkins.

Yes, if this isn't failing in the full MSBuild Jenkins run, then I think it's not testing what we think it is (since the corresponding change to the NuGet targets isn't on the Jevkins machine). I'd like us to understand why this is the case.

You can run tests against full MSBuild locally with build -FullMSBuild.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

build -FullMSBuild did not fail.

Does "Full MSBuild" mean the sdk and targets under %VSINSTALLDIR% or under .dotnet_cli. I assume its under .dotnet_cli. In this case, these are the same "ImportAfter" targets used by the CLI i.e. they have already removed Microsoft.NuGet.targets (see .dotnet_cli\sdk\1.0.0-rc4-004771\15.0\Microsoft.Common.targets\ImportAfter\Microsoft.NuGet.ImportAfter.targets)

I inspected the project.assets.json generated for the test under bin\Debug\Tests, and it only contains one (ridless) targets entry, so the test is correctly passing, but would fail if we were using the MSBuild under %VSINSTALLDIR%.

Copy link
Contributor

Choose a reason for hiding this comment

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

Full msbuild means the one in VS. Pasting my comment to this thread as well:

I assume it's not failing because the Jenkins machines won't have the corresponding change in NuGet.targets that adds a condition to skip import with these properties. When we move Jenkins to a build with the VS side change then it'll start failing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK figured it out. For some reason, the multiple rid problem only repros on apps targeting netcoreapp1.0, not on libraries targeting netstandard1.5. I guess some combination of the conditions in Microsoft.NuGet.targets is only affecting these projects, but its not obvious which ones. (To confirm, New NetStandard Library -> Add System.ValueTuple, does not produce any warnings.)

I've moved the test to GivenThatWeWantToBuildANetCoreApp and modified it to check values from the HelloWorld app. Now build passes, but build -FullMSBuild fails. I'll push this change to confirm Jenkins fails, then disable the test until we update Jenkins.

@nguerrera
Copy link
Contributor

The downgrade warnings occur because more RIDs are restored than are specified because of this property in Microsoft.NuGet.targets:

So the downgrades will still occur for projects that add RIDs themselves? If so, this only lessens the case where you'll see them and we still haven't gotten to the root of the issue. I thought there was actually a problem with the authoring of packages like System.ValueTuple.

I just needed to separately add default RIDs to restore of multitargeting project for #847, so if I've understood, the same behavior would show up in that case (only deterministically in both VS and CLI).

@srivatsn
Copy link
Contributor

Yes this only lessens the situations where this happens. The ValueTuple package itself is being fixed and #821 tracks doing something about the downgrade warnings for other packages (not sure what).

@davidfowl
Copy link
Member

Wow this will fix the 5000 warnings we kept seeing in corefxlab! /cc @pakrym

@pakrym
Copy link
Contributor

pakrym commented Feb 15, 2017

@davidfowl those were fixed by dotnet/corefxlab#1218 but this fixes the root cause

@natidea
Copy link
Contributor Author

natidea commented Feb 15, 2017

@dotnet-bot test this please

@srivatsn
Copy link
Contributor

Tagging @MattGertz for approval.

@@ -577,5 +577,15 @@ public void It_passes_ridless_target_to_compiler()
.Should()
.Pass();
}

[Fact]
public void It_restores_only_ridless_tfm()
Copy link
Member

Choose a reason for hiding this comment

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

I think you'll get coverage from the full msbuild runs in Jenkins.

Yes, if this isn't failing in the full MSBuild Jenkins run, then I think it's not testing what we think it is (since the corresponding change to the NuGet targets isn't on the Jevkins machine). I'd like us to understand why this is the case.

You can run tests against full MSBuild locally with build -FullMSBuild.

@srivatsn
Copy link
Contributor

I assume it's not failing because the Jenkins machines won't have the corresponding change in NuGet.targets that adds a condition to skip import with these properties. When we move Jenkins to a build with the VS side change then it'll start failing

@natidea
Copy link
Contributor Author

natidea commented Feb 15, 2017

@srivatsn its the other way round. The test expects only one target definition. If we were running with MSBuild under %VSINSTALLDIR% we would get 3 target definitions, until we apply the VS-side change.

@srivatsn
Copy link
Contributor

Ah yes.. then I agree with Daniel. It's fishy that it isn't failing with the full msbuild.

@natidea
Copy link
Contributor Author

natidea commented Feb 16, 2017

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

LGTM. You could disable the test only when running on full framework, as we do here, for example.

@natidea
Copy link
Contributor Author

natidea commented Feb 16, 2017

Approved to merge via 385238

mmitche pushed a commit to mmitche/sdk that referenced this pull request Jun 5, 2020
…0190811.2 (dotnet#870)

- Microsoft.AspNetCore.Mvc.Analyzers - 3.0.0-preview9.19411.2
- Microsoft.AspNetCore.Mvc.Api.Analyzers - 3.0.0-preview9.19411.2
- Microsoft.AspNetCore.Analyzers - 3.0.0-preview9.19411.2
- Microsoft.AspNetCore.Components.Analyzers - 3.0.0-preview9.19411.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NuGet restore in Visual Studio restores for multiple rids
8 participants