1
votes

We have set up a Project in Visual Studio where we are using NuGet Packages references. For one of the NuGet Packages we are setting the GeneratePathProperty to true, so that we can copy the files from the NuGet package location to the Output bin folder of our Project

He have configured the .csproj file as below:

<PackageReference Include="ilmerge" GeneratePathProperty="true">
  <Version>3.0.29</Version>
</PackageReference>
<None Include="$(Pkgilmerge)\tools\net452\ILMerge.exe">
  <Link>ILMerge.exe</Link>
  <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="$(Pkgilmerge)\tools\net452\System.Compiler.dll">
  <Link>System.Compiler.dll</Link>
  <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

This works perfectly fine locally (using Visual Studio 2019) - project compiles and files are copied to the bin folder, however in our Build Pipeline using the windows-2019 hosted agent (that should also have VS 2019 as per the documentation https://github.com/actions/virtual-environments/blob/master/images/win/Windows2019-Readme.md) this fails during the Build Task:

[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4601,5): Error MSB3030: Could not copy the file 'd:\tools\net452\ILMerge.exe' because it was not found.

[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4601,5): Error MSB3030: Could not copy the file 'd:\tools\net452\System.Compiler.dll' because it was not found.

The Build Definition has following tasks

steps:
- task: NuGetToolInstaller@0
- task: NuGetCommand@2
  displayName: 'Restore Nugets'
  inputs:
    restoreSolution: '$(solutions)'
    vstsFeed: 'Project-Packages'

- task: VSBuild@1
  inputs:
    solution: '$(solutions)'
    platform: 'Any CPU'
    configuration: 'Release'
    logProjectEvents: false

- task: PublishBuildArtifacts@1
  inputs:
    pathtoPublish: '$(Build.StagingDirectory)'
    artifactName: $(pluginName)
  condition: always()

Any ideas what could be the issue or what we need to change in order for the build in Azure DevOps to work?

Later Edit: I added some logging

  <Target Name="¨ReMerge" AfterTargets="ILRepacker" >
    <Message Text="Remerging Assemblies using ILMerge from $(Pkgilmerge) and setting AssemblyVersion = 2.0.0.0" Importance="High" />
    <Exec Command="dir $(Pkgilmerge)"></Exec>
    <Exec Command="$(Pkgilmerge)\tools\net452\ILMerge.exe /ver:2.0.0.0 /out:$(TargetDir)$(TargetName)Merged.dll /keyfile:$(ProjectDir)Zurich.Zkp.Key.snk $(TargetDir)$(TargetName)MergedTemp.dll"></Exec>
  </Target>

And it seems that in AzureDevops the $(Pkgilmerge) is empty

Thank you

1

1 Answers

3
votes

The above error was caused by an old version(4.x) Nuget being used to restore your solution.

You need to specify the Nuget version to the newest for your NuGetToolInstaller task, if unspecified, a version will be chosen automatically.

Check below example to specify NuGetToolInstaller task to use 5.4.x version of Nuget.

- task: NuGetToolInstaller@0
  inputs:
    versionSpec: 5.4.x