dotnet构建找不到Xamarin

f45qwnt8  于 2023-01-28  发布在  其他
关注(0)|答案(2)|浏览(173)

在我的项目中运行dotnet build时,我遇到了以下错误:

/path/to/repo/Toolkit/My.Company.Toolkit.Platform.Android/My.Company.Toolkit.Platform.Android.csproj(91,3): error MSB4019: The imported project "/usr/local/share/dotnet/sdk/7.0.102/Xamarin/Android/Xamarin.Android.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/usr/local/share/dotnet/sdk/7.0.102//Xamarin/Android/Xamarin.Android.CSharp.targets" is correct, and that the file exists on disk.
/path/to/repo/Toolkit/My.Company.Toolkit.Platform.iOS/My.Company.Toolkit.Platform.iOS.csproj(195,3): error MSB4019: The imported project "/usr/local/share/dotnet/sdk/7.0.102/Xamarin/iOS/Xamarin.iOS.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/usr/local/share/dotnet/sdk/7.0.102//Xamarin/iOS/Xamarin.iOS.CSharp.targets" is correct, and that the file exists on disk.

我确认/usr/local/share/dotnet/sdk/7.0.102/Xamarin/iOS/Xamarin.iOS.CSharp.targets不存在。
但我不知道怎么安装。
Xamarin的参考在csproj中定义如下<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
当我从Visual Studio构建时,我没有任何问题。如果我试图重新安装Xamarin,它会说它已经安装了。
我在MacOS上。

  • [更新]*

我卸载了所有的东西(VisualStudio、SDK/Runtime、DotNet等)。只安装了VisualStudio 2022 for Mac。

➜  ~ dotnet --info
.NET SDK:
 Version:   7.0.102
 Commit:    4bbdd14480

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  13.1
 OS Platform: Darwin
 RID:         osx.13-arm64
 Base Path:   /usr/local/share/dotnet/sdk/7.0.102/

Host:
  Version:      7.0.2
  Architecture: arm64
  Commit:       d037e070eb

.NET SDKs installed:
  6.0.405 [/usr/local/share/dotnet/sdk]
  7.0.102 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

现在,如果我尝试在终端中构建项目,我仍然会遇到同样的错误。但如果我尝试从Visual Studio中构建它,我会遇到不同的错误。
我在生成输出中遇到此错误

Target RazorGenerateComponentDeclaration:
    /usr/local/share/dotnet/dotnet exec "/Users/redacted/Library/Caches/VisualStudio/17.0/MSBuild/36265_3/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/../../tools/netcoreapp3.0/rzc.dll" generate
    -s
    /Users/redacted/Developer/repositories/bcee/Toolkit/MyCompany.Toolkit.Platform.Web/_Imports.razor
    -r
    _Imports.razor
    -o
    /Users/redacted/Developer/repositories/bcee/Toolkit/MyCompany.Toolkit.Platform.Web/obj/Debug/netstandard2.1/RazorDeclaration/_Imports.razor.g.cs
    -k
    component
    -p
    /Users/redacted/Developer/repositories/bcee/Toolkit/MyCompany.Toolkit.Platform.Web
    -t
    obj/Debug/netstandard2.1/MyCompany.Toolkit.Platform.Web.RazorComponents.declaration.json
    -v
    3.0
    -c
    Default
    --root-namespace
    MyCompany.Toolkit.Web
    --csharp-language-version
    8.0
    --generate-declaration
    
    The application to execute does not exist: '/Users/redacted/Library/Caches/VisualStudio/17.0/MSBuild/36265_3/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/../../tools/netcoreapp3.0/rzc.dll'
    /Users/redacted/Library/Caches/VisualStudio/17.0/MSBuild/36265_3/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Component.targets(106,5): error : rzc generate exited with code 129.
Done building target "RazorGenerateComponentDeclaration" in project "MyCompany.Toolkit.Platform.Web.csproj" -- FAILED.

Done building project "MyCompany.Toolkit.Platform.Web.csproj" -- FAILED.

Build FAILED.

工具目录不存在。

yhuiod9q

yhuiod9q1#

一开始,你说:
当我从Visual Studio构建时,我没有任何问题。
原因应该是当您从Visual Studio生成时。您的项目使用的框架是.netstandard 2.0。您可以在**/usr/local/share/dotnet/sdk**中检查项目.csproj文件和SDK。
另外,你可以检查this case which has the similar error as yours。根据它,如果.net版本与xamarin不兼容,也会得到这个错误。dotnet/sdk/7.0.102应该是与.net maui兼容的.net 7,而不是xamarin。所以你不能使用dotnet构建项目。
您可以尝试找到MSBuildExtensionsPath的正确值,并根据this case which is about set the project's MSBuildExtensionsPath在android和ios .csproj文件中设置它。
最后,您可以在this case which has the same error message中尝试该解决方案。

bjp0bcyl

bjp0bcyl2#

Xamarin工具链是基于Mono构建的,因此您在VS for Mac中触发的所有内容都由MSBuild for Mono友好地处理(在Mac终端,您可以使用msbuild --version了解更多信息)。
然而,dotnet build是专门为基于.NET Core的项目设计的,所以默认情况下它不能处理Xamarin项目,只能处理.NET MAUI。
由于遗留的Xamarin项目即将消失,您应该尽快开始迁移到MAUI,
https://dotnet.microsoft.com/en-us/platform/support/policy/xamarin

相关问题