为 PackageReference 使用 GeneratePathProperty true 时,Azure Devops 构建失败
Azure Devops Build Fail when using GeneratePathProperty true for PackageReference
我们在 Visual Studio 中建立了一个项目,我们在其中使用 NuGet 包引用。对于其中一个 NuGet 包,我们将 GeneratePathProperty 设置为 true,以便我们可以将文件从 NuGet 包位置复制到我们项目的输出 bin 文件夹
他配置了 .csproj 文件如下:
<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>
这在本地工作得很好(使用 Visual Studio 2019)- 项目编译和文件被复制到 bin 文件夹,但是在我们的构建管道中使用 windows-2019 托管代理(应该根据文档 https://github.com/actions/virtual-environments/blob/master/images/win/Windows2019-Readme.md 也有 VS 2019)在构建任务期间失败:
[error]C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4601,5): 错误 MSB3030: 无法复制文件 'd:\tools\net452\ILMerge.exe' 因为没有找到。
[error]C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4601,5): 错误 MSB3030: 无法复制文件 'd:\tools\net452\System.Compiler.dll' 因为没有找到。
构建定义有以下任务
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()
任何想法可能是什么问题或我们需要更改什么才能使 Azure DevOps 中的构建工作?
稍后编辑:我添加了一些日志记录
<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>
而且在 AzureDevops 中 $(Pkgilmerge) 似乎是空的
谢谢
上述错误是由于使用旧版本 (4.x) Nuget 来恢复您的解决方案造成的。
您需要为您的 NuGetToolInstaller 任务指定最新的 Nuget 版本,如果未指定,将自动选择一个版本。
检查以下示例以指定 NuGetToolInstaller 任务使用 5.4.x 版本的 Nuget。
- task: NuGetToolInstaller@0
inputs:
versionSpec: 5.4.x
我们在 Visual Studio 中建立了一个项目,我们在其中使用 NuGet 包引用。对于其中一个 NuGet 包,我们将 GeneratePathProperty 设置为 true,以便我们可以将文件从 NuGet 包位置复制到我们项目的输出 bin 文件夹
他配置了 .csproj 文件如下:
<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>
这在本地工作得很好(使用 Visual Studio 2019)- 项目编译和文件被复制到 bin 文件夹,但是在我们的构建管道中使用 windows-2019 托管代理(应该根据文档 https://github.com/actions/virtual-environments/blob/master/images/win/Windows2019-Readme.md 也有 VS 2019)在构建任务期间失败:
[error]C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4601,5): 错误 MSB3030: 无法复制文件 'd:\tools\net452\ILMerge.exe' 因为没有找到。
[error]C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4601,5): 错误 MSB3030: 无法复制文件 'd:\tools\net452\System.Compiler.dll' 因为没有找到。
构建定义有以下任务
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()
任何想法可能是什么问题或我们需要更改什么才能使 Azure DevOps 中的构建工作?
稍后编辑:我添加了一些日志记录
<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>
而且在 AzureDevops 中 $(Pkgilmerge) 似乎是空的
谢谢
上述错误是由于使用旧版本 (4.x) Nuget 来恢复您的解决方案造成的。
您需要为您的 NuGetToolInstaller 任务指定最新的 Nuget 版本,如果未指定,将自动选择一个版本。
检查以下示例以指定 NuGetToolInstaller 任务使用 5.4.x 版本的 Nuget。
- task: NuGetToolInstaller@0
inputs:
versionSpec: 5.4.x