【发布时间】:2020-04-22 00:43:16
【问题描述】:
当我尝试使用 Jenkins 构建更新的 Xamarin.Forms 项目时,我遇到了超过 1500 个这样的错误:
App.xaml.cs(24,32): 错误 CS0012: Der Typ "Object" ist in einer nicht referenzierten Assembly definiert。 Fügen Sie einen Verweis auf die Assembly "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" hinzu。
翻译错误:
CS0012:“System.Object”类型是在未引用的程序集中定义的。您必须添加对程序集 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' 的引用。
如果我在同一台机器上构建项目,但在 Visual Studio 2017 内它可以正常工作(就像在我的本地机器上一样)。 Jenkins 的构建命令如下所示
"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild" /p:ReferencePath=C:\jenkins\workspace\somelibrary\ SomeProject/SomeProject/SomeProject.csproj /t:Restore /p:Configuration=Release /t:Build
以前我updated to .NET Standard 2.0 和Xamarin.Forms 3.4.0.1039999。构建服务器本身在 Windows 10 1703Windows 10 1909 上运行。 我的(我read 如果你想一起使用Xamarin.Forms 项目中有UWP,但我并没有真正使用它。.NET Standard 2.0,至少需要Windows 10 1709 UWP.)
该项目还引用了一个NuGet 包,它与.NET Standard 2.0 尚不兼容。在这里我收到警告
警告 NU1701 包“xxx”是使用“.NETFramework,Version=v4.6.1”而不是项目目标框架“.NETStandard,Version=v2.0”恢复的。此软件包可能与您的项目不完全兼容。
这可能是出现一些问题的原因,因为它是not fully compatible。
我尝试了什么:
- 清理构建,删除
bin和obj文件夹 - 使用
<Reference Include="netstandard" />没有成功与Jenkins 一起构建。引用NETStandard.Library在我的本地构建环境中引发警告(但已安装) - 已将
Visual Studio Build Tools 2017和Visual Studio 2017更新到最新版本 (15.9.18) - 在构建服务器上安装了
.NET Core SDK、.NET Core Build Tools、.NET Framework 4.7.2 SDK - 用C:\Program Files\dotnet扩展
PATH环境变量,将全局环境变量MSBuildSDKsPath设置为C:\Program Files\dotnet\sdk\2.1.509\ SDK - 已删除 UWP 项目(仍存在于文件夹中,但不在 *.sln 中)
- 在其他用户遇到类似问题后进行了一些研究,但没有找到解决问题的方法
我观察到的:
- 使用
Visual Studio 2017在使用Windows 10 1703的构建服务器上构建项目可以正常工作 - 使用
Visual Studio 2017在我的本地计算机上使用Windows 10 1809构建项目可以正常工作 - 在构建服务器上使用
msbuild和命令行可以正常构建项目(NuGet 包正确引用 netstandard2.0 而不是 NuGetFallbackFolder 中的 netstandard1.3 等等)
我可以尝试什么:
将构建服务器更新为Windows 10 1709或更高版本- 替换/更新库,仍然使用
.NET 4.6.1 - 升级到
Visual Studio 2019 - 从头开始创建一个
.NET Standard项目并复制所有文件(并丢失GIT历史记录)
但我不明白的是,它在 Visual Studio 中运行良好,但在 msbuild/Jenkins 中运行良好。似乎缺少参考或未安装某些东西。
我该怎么办?
编辑:
从项目的 Xamarin.Forms 部分中提取 .csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<NeutralLanguage>en</NeutralLanguage>
<AssemblySearchPaths>
$(AssemblySearchPaths);
$(ReferencePath);
</AssemblySearchPaths>
</PropertyGroup>
<ItemGroup>
<None Remove="picture.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Plugin" Version="5.2.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="SomeLibrary">
<HintPath>pat\to\library\netstandard2.0\SomeLibrary.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Update="Common\Localization\AppResources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>AppResources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Common\Localization\AppResources.de.resx">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Update="Common\Localization\AppResources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>AppResources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="App.xaml">
<Generator>MSBuild:Compile</Generator>
</None>
<None Update="SomePage.xaml">
<Generator>MSBuild:Compile</Generator>
</None>
</ItemGroup>
</Project>
【问题讨论】:
-
您可以分享您的
csproj文件中的引用吗? -
@PavelAnikhouski:我编辑了我的问题。如果您需要什么,请告诉我。特定于平台的 csproj 看起来不同(旧格式)。
-
哪个包导致
Warning NU1701错误?另外,你是如何恢复包和构建源的,使用了哪些命令?这个thread 也可能有帮助 -
@PavelAnikhouski:XLog。如上所示,使用
msbuild和/t:Restore完成恢复。在构建过程中涉及到很多事情。主要部分包括首先使用msbuild /p:ReferencePath=xxx SomeProject/SomeProject/SomeProject.csproj /t:Restore /p:Configuration=Release /t:Build构建Xamarin.Forms 项目,然后使用msbuild /p:ReferencePath=xxx SomeProject/SomeProject.Droid/SomeProject.Droid.csproj /p:Configuration=Release /t:Restore /t:PackageForAndroid /t:Build构建Android 项目。但他在第一步就犯了错误 -
PATH环境变量指向构建服务器上的C:\Program Files\dotnet。
标签: .net visual-studio jenkins xamarin.forms .net-standard-2.0