构建引用Xamarin.Forms的.net标准应用程序

问题描述 投票:1回答:1

我正在尝试使用Visual Studio Code将Windows.Forms应用程序移植到.Net Standard 2.0。根据对早期问题的回答(谢谢你们),我的计划是尝试使用Xamarin.Forms替换System.Windows.Forms。所以,我将Xamarin.Forms包添加到我的项目中。当我尝试运行dotnet build时,我看到以下错误:

C:\Users\<user>\.nuget\packages\xamarin.forms\2.4.0.38779\build\netstandard1.0\Xamarin.Forms.targets(51,3): error MSB4062: The "Xamarin.Forms.Build.Tasks.FixedCreateCSharpManifestResourceName" task could not be loaded from the assembly C:\Users\<user>\.nuget\packages\xamarin.forms\2.4.0.38779\build\netstandard1.0\Xamarin.Forms.Build.Tasks.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

我试图添加各种其他Microsoft.Build包,但似乎没有任何工作。这里有前进的方向吗?这是我当前的csproj文件:

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Microsoft.Build" Version="15.3.409" />
<PackageReference Include="Microsoft.Build.Framework" Version="15.3.409" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="15.3.409" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.3.409" />
<PackageReference Include="NUnit" Version="3.8.1" />
<PackageReference Include="System.Configuration" Version="2.0.5" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.0" />
<PackageReference Include="System.ServiceModel" Version="1.0.0" />
<PackageReference Include="Xamarin.Forms" Version="2.4.0.38779" />
</ItemGroup>

</Project>

我想我可能会问这里的问题:Where is the difference of dotnet build on cmd vs VS2017?但不确定。

c# xamarin xamarin.forms msbuild .net-standard-2.0
1个回答
0
投票

我正在开发一个Xamarin.Forms应用程序,我正在将我的库从PCL迁移到NetStandard。

您似乎可以使用MsBuild.exe构建项目(我使用C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Enterprise \ MSBuild \ 15.0 \ Bin \ MSBuild.exe)。

我发现它在这篇博文中提到:https://oren.codes/2017/04/23/using-xamarin-forms-with-net-standard-vs-2017-edition/

您需要使用MSBuild.exe来构建它,可以在Windows上使用VS 2017命令提示符,也可以在Mac上使用Visual Studio for Mac。您不能对这些项目类型使用dotnet构建。 dotnet build仅支持.NET Standard,.NET Core和.NET Framework项目类型。它无法构建Xamarin项目,并且Xamarin Forms中的自定义任务尚未更新以支持.NET Core。

另外需要注意:我必须删除AssemblyInfo.cs,否则MsBuild会抱怨重复的属性。

© www.soinside.com 2019 - 2024. All rights reserved.