dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.23k stars 1.35k forks source link

While generating the restore graph file add the location to where the package dependency version is specified #3770

Open msschl opened 6 years ago

msschl commented 6 years ago

Explanation

I am using Directory.Build.props files to define package references and declare version variables (e.g. <MoqPackageVersion>4.9.0</MoqPackageVersion>) and reference this version variable in a Project.csproj (like <PackageReference Include="Moq" Version="$(MoqPackageVersion)" />).

It would be nice to include the location to the specific .props file in the restore graph from where the package was referenced or the version was specified. This enables other tools to update package version for projects that are specifing package versions through .props files.

Test Project file

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPackageVersion)" />
    <PackageReference Include="Moq" Version="$(MoqPackageVersion)" />
    <PackageReference Include="xunit" Version="$(XunitPackageVersion)" />
    <PackageReference Include="xunit.runner.visualstudio" Version="$(XunitRunnerVisualStudioPackageVersion)" />
    <PackageReference Include="xunit.analyzers" Version="$(XunitAnalyzersPackageVersion)" />
    <PackageReference Include="coverlet.msbuild" Version="$(CoverletMSBuildPackageVersion)">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <DotNetCliToolReference Include="dotnet-xunit" Version="$(DotNetXunitPackageVersion)" />
  </ItemGroup>

</Project>

Solution directory contents:

/
- build/
     - dependencies.props
     - sources.props
- src/
     - Project1/
          - Project1.csproj
          - Program.cs
     - Project2/
          - Project2.csproj
          - Program.cs
     - Directory.Build.props
- test/
     - Project1.Tests/
          - Project1.Tests.csproj
          - Test.cs
     - Project2.Tests/
          - Project2.Tests.csproj
          - Test.cs
     - Directory.Build.props
- Directory.Build.props
- Directory.Build.targets
- Project.sln
- NuGet.config <!-- Clears all package sources! Restore sources should be defined in build/sources.props. -->
- version.props

Command line

msbuild PROJECT_PATH /t:GenerateRestoreGraphFile /p:RestoreGraphOutputPath=TEMP_FILE_LOCATION

Environment data

msbuild /version output:

Microsoft (R)-Buildmodul, Version 4.7.3056.0 [Microsoft .NET Framework, Version 4.0.30319.42000] Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

4.7.3056.0

OS info: Edition: Windows 10 Pro Version: 1803 Build: 17134.285

dotnet --info .NET Core SDK (reflecting any global.json): Version: 2.1.402 Commit: 3599f217f4

Runtime Environment: OS Name: Windows OS Version: 10.0.17134 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.1.402\

Host (useful for support): Version: 2.1.4 Commit: 85255dde3e

.NET Core SDKs installed: 1.0.4 [C:\Program Files\dotnet\sdk] 1.1.10 [C:\Program Files\dotnet\sdk] 2.0.0 [C:\Program Files\dotnet\sdk] 2.0.2 [C:\Program Files\dotnet\sdk] 2.1.2 [C:\Program Files\dotnet\sdk] 2.1.104 [C:\Program Files\dotnet\sdk] 2.1.105 [C:\Program Files\dotnet\sdk] 2.1.201 [C:\Program Files\dotnet\sdk] 2.1.202 [C:\Program Files\dotnet\sdk] 2.1.300-preview2-008533 [C:\Program Files\dotnet\sdk] 2.1.300-rc1-008673 [C:\Program Files\dotnet\sdk] 2.1.300 [C:\Program Files\dotnet\sdk] 2.1.301 [C:\Program Files\dotnet\sdk] 2.1.302 [C:\Program Files\dotnet\sdk] 2.1.400 [C:\Program Files\dotnet\sdk] 2.1.401 [C:\Program Files\dotnet\sdk] 2.1.402 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.0-preview2-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.0-rc1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.0-preview2-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.0-rc1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.0-preview2-26406-04 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.0-rc1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

rainersigwald commented 6 years ago

Thanks for the suggestion @msschl!

MSBuild doesn't preserve that level of provenance information for items in the MSBuild execution model. A program using the MSBuild APIs to evaluate and build projects could get back to the XML element that created an item, but we don't expose that through item metadata. Even in the API case, we wouldn't have enough information to identify the property definition used to define the item metadata.

@rrelyea -- fyi, a NuGet scenario request that would hinge on a (pretty big) MSBuild feature.

I'm inclined to say that while this would be useful, it's not worth the cost, and close this.

msschl commented 5 years ago

Anything planned on this feature request?