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

ReferenceCopyLocalPaths no longer content NuGetSourceType metadata #4754

Closed
joeltankam opened this issue Sep 20, 2019 · 1 comment
Closed
Labels

Comments

@joeltankam
Copy link

Steps to reproduce

I encounter some missing metadata to ReferenceCopyLocalPaths item since migrating to Microsoft.NET.Sdk format in project files.

Lets consider the following project file :

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

  <PropertyGroup>
    <TargetFramework>net471</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
  </ItemGroup>

</Project>

I use the following code to print metadata from ReferenceCopyLocalPaths items :

  <UsingTask TaskName="GetMetadataTask" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
    <ParameterGroup>
      <Items ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
      <MetadataString Output="true" />
    </ParameterGroup>
    <Task>
      <Using Namespace="System"/>
      <Code Type="Fragment" Language="cs">
        <![CDATA[
            StringBuilder metadata = new StringBuilder();
            foreach (var item in Items)
            {
                metadata.AppendFormat("{0}\r\n", item);
                foreach (string name in item.MetadataNames)
                {
                    metadata.AppendFormat("  {0}={1}\r\n", name, item.GetMetadata(name));
                }
                metadata.AppendFormat("\r\n");
            }
            MetadataString = metadata.ToString();
        ]]>
      </Code>
    </Task>
  </UsingTask>

  <Target Name="_SetNuGetSourceTypeToCopyLocal" AfterTargets="ResolveAssemblyReferences">
    <ItemGroup>
      <PrintItems Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' != ''" />
    </ItemGroup>
    <GetMetadataTask Items="@(PrintItems)">
      <Output TaskParameter="MetadataString" PropertyName="MyBeautifulMetadata"/>
    </GetMetadataTask>
    <Message Importance="High" Text="$(MyBeautifulMetadata)" />
  </Target>

Expected behavior

When using old project files format, I had the following metadata :

  ItemName=C:\Users\joel.tankam\.nuget\packages\newtonsoft.json\12.0.2\lib\net45\Newtonsoft.Json.dll
    NuGetPackageId=Newtonsoft.Json
    NuGetPackageVersion=12.0.2
    Private=false
    NuGetIsFrameworkReference=false
    NuGetSourceType=Package
    FullPath=C:\Users\joel.tankam\.nuget\packages\newtonsoft.json\12.0.2\lib\net45\Newtonsoft.Json.dll
    RootDir=C:\
    Filename=Newtonsoft.Json
    Extension=.dll
    RelativeDir=C:\Users\joel.tankam\.nuget\packages\newtonsoft.json\12.0.2\lib\net45\
    Directory=Users\joel.tankam\.nuget\packages\newtonsoft.json\12.0.2\lib\net45\
    RecursiveDir=
    Identity=C:\Users\joel.tankam\.nuget\packages\newtonsoft.json\12.0.2\lib\net45\Newtonsoft.Json.dll
    ModifiedTime=2019-04-22 01:06:16.0000000
    CreatedTime=2019-09-18 10:16:19.6451378
    AccessedTime=2019-09-18 10:16:19.6451378
    DefiningProjectFullPath=C:\MyBeautifulProject\Project.csproj
    DefiningProjectDirectory=C:\MyBeautifulProject\
    DefiningProjectName=Project
    DefiningProjectExtension=.csproj

Actual behavior

Now I get the following :

ItemName=C:\Users\joel.tankam\.nuget\packages\newtonsoft.json\12.0.2\lib\net45\Newtonsoft.Json.dll
    NuGetPackageId=Newtonsoft.Json
    NuGetPackageVersion=12.0.2
    FullPath=C:\Users\joel.tankam\.nuget\packages\newtonsoft.json\12.0.2\lib\net45\Newtonsoft.Json.dll
    RootDir=C:\
    Filename=Newtonsoft.Json
    Extension=.dll
    RelativeDir=C:\Users\joel.tankam\.nuget\packages\newtonsoft.json\12.0.2\lib\net45\
    Directory=Users\joel.tankam\.nuget\packages\newtonsoft.json\12.0.2\lib\net45\
    RecursiveDir=
    Identity=C:\Users\joel.tankam\.nuget\packages\newtonsoft.json\12.0.2\lib\net45\Newtonsoft.Json.dll
    ModifiedTime=2019-04-22 01:06:16.0000000
    CreatedTime=2019-09-18 10:16:19.6451378
    AccessedTime=2019-09-18 10:16:19.6451378
    DefiningProjectFullPath=C:\MyBeautifulProject\Project.csproj
    DefiningProjectDirectory=C:\MyBeautifulProject\
    DefiningProjectName=Project
    DefiningProjectExtension=.csproj

The difference being the absence of :

    Private=false
    NuGetIsFrameworkReference=false
    NuGetSourceType=Package

However, I need the NuGetSourceType metadata in my build process.
Is there please any reason why this this metadata disappeared ? Is there a way to set it back ?

I currently use this custom target to set back NuGetSourceType :

  <Target Name="_SetNuGetSourceTypeToCopyLocal" AfterTargets="ResolveReferences">
    <ItemGroup>
      <ReferenceCopyLocalPaths Update="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' != ''">
        <NuGetSourceType>Package</NuGetSourceType>
      </ReferenceCopyLocalPaths>
    </ItemGroup>
  </Target>

Environment data

msbuild /version output: 15.9.21.664
.NET Core SDK version : 2.2.108
Visual Studio : Professional 2017, v 15.9.16

@rainersigwald
Copy link
Member

This issue was moved to dotnet/sdk#3662

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants