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

Project.nuget.g.targets should not prepend to MSBuildAllProjects in MSBuild 16 or later #10895

Closed
drewnoakes opened this issue May 26, 2021 · 1 comment · Fixed by NuGet/NuGet.Client#4168
Assignees
Labels
Category:Quality Week Issues that should be considered for quality week Priority:2 Issues for the current backlog. Style:PackageReference Tenet:Performance Performance issues Type:DCR Design Change Request

Comments

@drewnoakes
Copy link

Testing using VS 17 internal preview, but I suspect this goes way back.

For a new .NET 5.0 xUnit project, the following obj\TestProject1.csproj.nuget.g.targets file is generated:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
  </PropertyGroup>
  <ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
    <Import Project="$(NuGetPackageRoot)xunit.core\2.4.1\build\xunit.core.targets" Condition="Exists('$(NuGetPackageRoot)xunit.core\2.4.1\build\xunit.core.targets')" />
    <Import Project="$(NuGetPackageRoot)microsoft.codecoverage\16.7.1\build\netstandard1.0\Microsoft.CodeCoverage.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.codecoverage\16.7.1\build\netstandard1.0\Microsoft.CodeCoverage.targets')" />
    <Import Project="$(NuGetPackageRoot)microsoft.net.test.sdk\16.7.1\build\netcoreapp2.1\Microsoft.NET.Test.Sdk.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.net.test.sdk\16.7.1\build\netcoreapp2.1\Microsoft.NET.Test.Sdk.targets')" />
    <Import Project="$(NuGetPackageRoot)coverlet.collector\1.3.0\build\netstandard1.0\coverlet.collector.targets" Condition="Exists('$(NuGetPackageRoot)coverlet.collector\1.3.0\build\netstandard1.0\coverlet.collector.targets')" />
  </ImportGroup>
</Project>

The MSBuildAllProjectsproperty does not need to be updated with MSBuildThisFileFullPath. There have been several changes over the last few years to stop adding projects to this, as the property can become very large which has an impact on runtime performance.

For more information, see:

To make this work with MSBuild versions earlier than 16, the following could be generated instead:

-    <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
+    <MSBuildAllProjects Condition=" '$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0' ">
+      $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
+    </MSBuildAllProjects>
@drewnoakes
Copy link
Author

Looks like it's coming from this code:

https://github.com/NuGet/NuGet.Client/blob/5c0589b7137106a7815299952d336bf5fd4a7e95/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/BuildAssetsUtils.cs#L191-L195

Also, there are many usages of this property throughout the NuGet org's code, which could be removed.

https://github.com/search?q=org%3ANuGet+MSBuildAllProjects&type=Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category:Quality Week Issues that should be considered for quality week Priority:2 Issues for the current backlog. Style:PackageReference Tenet:Performance Performance issues Type:DCR Design Change Request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants
@drewnoakes @dominoFire @erdembayar @heng-liu @aortiz-msft and others