我有一个针对 .net 4.7.2 的 sdk 风格项目
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
</Project>
其中只有一个类,并且没有依赖项。
我可以在 Visual Studio 中构建和发布项目。
我现在使用以下构建管道
trigger:
- main
pool:
vmImage: windows-latest
steps:
- task: DotNetCoreCLI@2
inputs:
command: 'restore'
projects: 'DotnetApp.sln'
feedsToUse: 'select'
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: 'DotnetApp.sln'
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
projects: 'DotnetApp.sln'
arguments: ' --arch x64 --no-restore -f net472 '
这会导致错误
C:\Program Files\dotnet\sdk .0.400\Sdks\Microsoft.NET.Sdk argets\Microsoft.PackageDependencyResolution.targets(266,5):错误NETSDK1047:资产文件'D:\s\obj\project .assets.json' 没有'net472/win-x64' 的目标。确保恢复已运行并且您已将“net472”包含在项目的 TargetFrameworks 中。您可能还需要在项目的 RuntimeIdentifiers 中包含“win-x64”。
我确实需要在发布步骤中使用 --no-restore 。没有它,发布步骤就可以工作。
这是因为您指定必须使用
--arch x64
参数发布特定于运行时的项目,但之前没有做好任何准备来确保此操作所需的资产到位。
您有两个选择:
RuntimeIdentifiers
(复数):正如错误消息所示:
您可能还需要在项目的运行时标识符中包含“win-x64”。
您可以将此预期的运行时标识符添加到您的项目文件中,以便
restore
任务将确保所需的资源就位:
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
</PropertyGroup>
--arch x64
。只要您没有特定于 x64 的代码(例如,需要 64 位的本机依赖项或手动实现的互操作调用)并且 可以在纯 32 位环境中执行,则可以省略。