Skip to content

[Microsoft.Build.NoTargets] GlobalPackageReferences are ignored for *.proj files #407

@dfederm

Description

@dfederm

For *.proj files, GlobalPackageReferences are not picked up.

Repro

Foo.proj:

<Project Sdk="Microsoft.Build.NoTargets/3.6.0">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>
  <ItemGroup>
    <Artifact Include="$(MSBuildThisFile)">
      <DestinationFolder>$(BaseOutputPath)</DestinationFolder>
    </Artifact>
  </ItemGroup>
</Project>

Directory.Packages.props:

<Project>
  <ItemGroup>
    <GlobalPackageReference Include="Microsoft.Build.Artifacts" Version="4.1.0" />
  </ItemGroup>
</Project>

Run msbuild /restore and notice that bin\Debug\netstandard2.0\Foo.proj does not exist despite the Artifact item.

Analysis

Looking at binlogs, the issue seems to be that there is a Microsoft.Managed.DesignTime.targets which overrides the CollectPackageReferences target, which is the target which handles GlobalPackageReferences.

Note that if the project extension is .csproj instead, it will actually work due to the import ordering being different.

Import order for proj file:

image

Import order for csproj file:

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions