问题描述
长话短说,我能够在 windows 2019 azure 托管代理以及 ubuntu 代理上成功构建一个 bitbucket .NET/MVC/Angular 项目。我想在 ubuntu 上构建它的原因是因为我注意到构建时间比 windows 代理快得多,考虑到平台,这是有道理的。
我在 Ubuntu 20 azure 托管代理上遇到此警告:
warning MSB3245: Could not resolve this reference. Could not locate the assembly "System.IdentityModel.Services". Check to make sure the assembly exists on disk. If this reference is required by your code,you may get compilation errors.
我在 Windows 2019 代理上没有收到此警告,而且我看到 .csproj
文件中已包含一个参考:
<Reference Include="System.IdentityModel.Services" />
<package id="Microsoft.IdentityModel.JsonWebTokens" version="5.2.4" targetFramework="net471" />
<package id="Microsoft.IdentityModel.Logging" version="5.2.4" targetFramework="net471" />
<package id="Microsoft.IdentityModel.Protocols" version="5.2.4" targetFramework="net471" />
<package id="Microsoft.IdentityModel.Protocols.OpenIdConnect" version="5.2.4" targetFramework="net471" />
<package id="Microsoft.IdentityModel.Tokens" version="5.2.4" targetFramework="net471" />
虽然构建工作正常,但我很想在 Ubuntu 代理上解决此警告,因为它没有出现在 Windows 2019 代理上。
到目前为止我的构建管道的屏幕截图:
解决方法
我们可以检查每个托管代理安装的软件,我们可以看到 Windows 2019 agent 已经安装了 .NET Framework 4.7.2 4.8 而它没有安装在 Ubuntu 20 azure hosted agent 上。
当无法找到或无法加载引用的程序集时,MSB3245 错误是典型的警告/错误。 System.IdentityModel.Services
是 .NET Framework 中的程序集。根据 doc:.NET Framework 是 .NET 的仅限 Windows 版本,用于构建在 Windows 上运行的任何类型的应用程序。
更新 1
我们可以看到Ubuntu 20 hosted agent已经安装了.NET Core SDK
,如果你想使用Ubuntu托管代理,你可以参考这个doc从.NET Framework
移植到{{ 1}},然后我们就可以在 .NET Core
注意:路漫漫其修远兮,我们还是建议您使用Window托管代理
,感谢这篇文章here:
将此脚本/行添加到 .csproj
文件:
<Import Project="..\packages\Microsoft.NETFramework.ReferenceAssemblies.net471.1.0.0\build\Microsoft.NETFramework.ReferenceAssemblies.net471.targets" Condition="Exists('..\packages\Microsoft.NETFramework.ReferenceAssemblies.net471.1.0.0\build\Microsoft.NETFramework.ReferenceAssemblies.net471.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information,see https://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.NETFramework.ReferenceAssemblies.net471.1.0.0\build\Microsoft.NETFramework.ReferenceAssemblies.net471.targets')" Text="$([System.String]::Format('$(ErrorText)','..\packages\Microsoft.NETFramework.ReferenceAssemblies.net471.1.0.0\build\Microsoft.NETFramework.ReferenceAssemblies.net471.targets'))" />
</Target>
另外你还需要在packages.config文件中加入这样的内容:
<package id="Microsoft.NETFramework.ReferenceAssemblies" version="1.0.0" targetFramework="net471" developmentDependency="true" />
<package id="Microsoft.NETFramework.ReferenceAssemblies.net471" version="1.0.0" targetFramework="net471" developmentDependency="true" />
有了它,它现在可以在 Ubuntu 上完美运行了!!! 只需查看这些持续时间差异,
- 在 Ubuntu 20 上为 2.5 分钟
- 8.5 分钟(Windows 2019)
疯了!