英文:
Missing netstandard 2.0 reference in Xamarin.Forms project when building with Jenkins
问题
我遇到了超过1500个类似的错误,当我尝试使用Jenkins构建更新的Xamarin.Forms
项目时:
>App.xaml.cs(24,32): error CS0012: 类型“Object”在未引用的程序集中定义。您必须添加对程序集“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
之前,我更新到了.NET Standard 2.0
和Xamarin.Forms 3.4.0.1039999
。构建服务器本身运行在<s>Windows 10 1703
</s>Windows 10 1909
上。<s>我的Xamarin.Forms
项目中包含UWP
,但我实际上没有使用它。</s>(我阅读说,如果要与UWP
一起使用.NET Standard 2.0
,至少需要Windows 10 1709
。)
该项目还引用了一个NuGet
包,该包尚不兼容.NET Standard 2.0
。这里我得到了警告:
>Warning NU1701: 包“xxx”是使用“.NETFramework, Version=v4.6.1”而不是项目目标框架“.NETStandard, Version=v2.0”恢复的。此包可能与您的项目不完全兼容。
这可能是一些问题的原因,因为它不是完全兼容。
我尝试过的事项:
- 清除构建,删除
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\Sdks - 删除了UWP项目(仍然存在于文件夹中,但不在*.sln中)
- 对来自其他用户的类似问题进行了一些研究,但没有找到解决问题的方法
我观察到的情况:
- 使用
Visual Studio 2017
在构建服务器上的Windows 10 1703
上构建项目正常 - 使用
Visual Studio 2017
在我本地机器上的Windows 10 1809
上构建项目正常 - 在构建服务器上使用
msbuild
和命令行构建项目正常(NuGet包正确引用了netstandard2.0而不是netstandard1.3等)
我可以尝试的事项:
- <s>将构建服务器升级到
Windows 10 1709
或更高版本</s> - 替换/更新仍然使用
.NET 4.6.1
的库 - 升级到
Visual Studio 2019
- 从头开始创建一个
.NET Standard
项目并复制所有文件(但会失去GIT
历史记录)
但我不明白的是,在Visual Studio
中一切正常,但在msbuild
/Jenkins
中不行。似乎缺少引用或某些内容没有安装。
我应该怎么办?
英文:
I'm getting over 1500 errors like this, when I try to build an updated Xamarin.Forms
project with Jenkins
:
>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.
Translated error:
>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'.
If I build the project with the same machine, but within Visual Studio 2017
it works without problems (as on my local machine). The build command for Jenkins
looks like this
"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
Previously I updated to .NET Standard 2.0
and Xamarin.Forms 3.4.0.1039999
. The build server itself is running on <s>Windows 10 1703
</s>Windows 10 1909
. <s>I have UWP
in my Xamarin.Forms
project, but I'm not really using it.</s> (I read that you need at least Windows 10 1709
if you want to use .NET Standard 2.0
together with UWP
.)
The project is also referencing a NuGet
package, which isn't compatible with .NET Standard 2.0
yet. Here I get the warning
>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.
This could be a reason why there are some problems, because it is not fully compatible.
What I tried:
- clean build, deleted
bin
andobj
folder - use of
<Reference Include="netstandard" />
without success at building with Jenkins. Reference toNETStandard.Library
throws a warning in my local build environment (but it is installed) - updated
Visual Studio Build Tools 2017
andVisual Studio 2017
to the latest version (15.9.18) - installed
.NET Core SDK
,.NET Core Build Tools
,.NET Framework 4.7.2 SDK
on the build server - extended
PATH
environment variable with C:\Program Files\dotnet, set global environment variableMSBuildSDKsPath
to C:\Program Files\dotnet\sdk\2.1.509\Sdks - deleted UWP project (still exists on folder, but not in *.sln)
- made some research after similar problems from other users, but didn't find something that solved the issue
What I observed:
- building the project works fine with
Visual Studio 2017
on the build server withWindows 10 1703
- building the project works fine with
Visual Studio 2017
on my local machine withWindows 10 1809
- building the project works fine with
msbuild
and command line on the build server (NuGet packages references correctly netstandard2.0 instead of netstandard1.3 and so on in the NuGetFallbackFolder)
What I could try:
- <s>update the build server to
Windows 10 1709
or higher</s> - replace/update the library, which still uses
.NET 4.6.1
- upgrade to
Visual Studio 2019
- create a
.NET Standard
project from scratch and copy all files over (and loosingGIT
history)
But what I don't get is that it is working fine in Visual Studio
but not with msbuild
/Jenkins
. Seems that a reference is missing or something is not installed.
What should I do?
Edit:
Extract of the .csproj from the Xamarin.Forms part of the project
<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>
答案1
得分: 0
我认为我用这个解决了它:
"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项目和特定平台项目执行此操作。
英文:
I think I solved it with this
"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
So the solution is to make two calls: one for restore
and one for build
. I do this for the Xamarin.Forms project and platform specific project separately.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论