【问题标题】:Building .net standard application that references Xamarin.Forms构建引用 Xamarin.Forms 的 .net 标准应用程序
【发布时间】:2017-11-06 18:53:34
【问题描述】:

我正在尝试使用 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? 但不确定。

【问题讨论】:

  • 您选择了netcoreapp2.0。这和netstandard2.0不一样
  • 是的,我实际上都试过了(netcoreapp2.0和netstandard2.0),但都报同样的错误。

标签: c# xamarin xamarin.forms msbuild .net-standard-2.0


【解决方案1】:

我正在开发一个 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 来构建它,无论是在带有 VS 2017 命令提示符的 Windows 上还是在带有 Visual Studio for Mac 的 Mac 上。您不能对这些项目类型使用 dotnet build。 dotnet build 仅支持 .NET Standard、.NET Core 和 .NET Framework 项目类型。它无法构建 Xamarin 项目,并且 Xamarin Forms 中的自定义任务尚未更新以支持 .NET Core。

附加说明:我必须删除 AssemblyInfo.cs,否则 MsBuild 会抱怨重复属性。

【讨论】:

    猜你喜欢
    • 2018-02-10
    • 2017-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-18
    • 2019-06-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多