使用 Jenkins 构建时 Xamarin.Forms 项目中缺少 netstandard 2.0 参考

Missing netstandard 2.0 reference in Xamarin.Forms project when building with Jenkins

当我尝试使用 Jenkins:

构建更新的 Xamarin.Forms 项目时,我遇到了超过 1500 个这样的错误

App.xaml.cs(24,32): error 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: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

如果我使用同一台机器构建项目,但在 Visual Studio 2017 内它可以正常工作(就像在我的本地机器上一样)。 Jenkins 的构建命令如下所示

"C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools\MSBuild.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 and Xamarin.Forms 3.4.0.1039999. The build server itself is running on Windows 10 1703Windows 10 1909. I have UWP in my Xamarin.Forms project, but I'm not really using it. (I 如果你想将 .NET Standard 2.0UWP 一起使用,你至少需要 Windows 10 1709。)

该项目还引用了一个 NuGet 包,它与 .NET Standard 2.0 尚不兼容。在这里我收到警告

Warning NU1701 Package 'xxx' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.

这可能是出现一些问题的原因,因为它是 not fully compatible

我尝试了什么:

我观察到的:

我可以尝试什么:

但我不明白的是,它在 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>

我想我用这个解决了

"C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools\MSBuild.0\Bin\MSBuild" SomeProject/SomeProject/SomeProject.csproj /t:Restore /p:Configuration=Release

"C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools\MSBuild.0\Bin\MSBuild" /p:ReferencePath=C:\jenkins\workspace\somelibrary\ SomeProject/SomeProject/SomeProject.csproj /p:Configuration=Release /t:Build

因此解决方案是调用两次:一次调用 restore,一次调用 build。我分别为 Xamarin.Forms 项目和平台特定项目执行此操作。