解决创建和构建.NET MAUI时的错误

tjjdgumg  于 2023-01-14  发布在  .NET
关注(0)|答案(1)|浏览(487)

**创建和构建.NET MAUI应用程序(.NET 6)时,出现以下错误。如何解决这些错误?Visual Studio 2022 version 17.4.2此问题是否与我国的Internet有关?(来自Iran)问题是否与我尚未安装的某些单个组件有关?Errors

Build
通过执行“dotnet workload restore”命令:

__________________________________________________
Project "S:\Projects\MauiApp1\MauiApp1\MauiApp1.csproj" (_GetRequiredWorkloads target(s)):

__________________________________________________
Project "S:\Projects\MauiApp1\MauiApp1\MauiApp1.csproj" is building "S:\Projects\MauiApp1\MauiApp1\MauiApp1.csproj" (_GetRequiredWorkloads target(s)):

C:\Program Files\dotnet\sdk\7.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1220,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\7.0.101\Sdks\Microsoft.NET.Sdk\16.1.1481\targets\Xamarin.Shared.Sdk.MultiTarget.targets" was not found. Confirm that the expression in the Import declaration ";..\16.1.1481\targets\Xamarin.Shared.Sdk.MultiTarget.targets;C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\6.0.547\Sdk\Microsoft.Maui.Sdk.After.targets;C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\6.0.547\Sdk\Microsoft.Maui.Core.Sdk.After.targets;C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\6.0.547\Sdk\Microsoft.Maui.Controls.Sdk.After.targets;C:\Program Files\dotnet\packs\Microsoft.Maui.Resizetizer.Sdk\7.0.49\Sdk\../targets/Microsoft.Maui.Resizetizer.targets" is correct, and that the file exists on disk.
Done building project "MauiApp1.csproj" -- FAILED.
__________________________________________________
Project "S:\Projects\MauiApp1\MauiApp1\MauiApp1.csproj" is building "S:\Projects\MauiApp1\MauiApp1\MauiApp1.csproj" (_GetRequiredWorkloads target(s)):

C:\Program Files\dotnet\sdk\7.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1220,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\7.0.101\Sdks\Microsoft.NET.Sdk\16.1.1481\targets\Xamarin.Shared.Sdk.MultiTarget.targets" was not found. Confirm that the expression in the Import declaration ";..\16.1.1481\targets\Xamarin.Shared.Sdk.MultiTarget.targets;C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\6.0.547\Sdk\Microsoft.Maui.Sdk.After.targets;C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\6.0.547\Sdk\Microsoft.Maui.Core.Sdk.After.targets;C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\6.0.547\Sdk\Microsoft.Maui.Controls.Sdk.After.targets;C:\Program Files\dotnet\packs\Microsoft.Maui.Resizetizer.Sdk\7.0.49\Sdk\../targets/Microsoft.Maui.Resizetizer.targets" is correct, and that the file exists on disk.
Done building project "MauiApp1.csproj" -- FAILED.
dotnet : Failed to restore workload for project S:\Projects\MauiApp1\MauiApp1\MauiApp1.csproj: Failed to run MSBuild Target _GetRequiredWorkloads.
At line:1 char:1
+ dotnet workload restore
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Failed to resto...uiredWorkloads.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

通过执行“Dotnet workload install wasm-tools”命令:

The machine has a pending reboot. Installation will continue, but you may need to restart.
Downloading microsoft.net.sdk.maui.manifest-7.0.100.msi.x64 (7.0.52)
Installing Microsoft.NET.Sdk.Maui.Manifest-7.0.100.7.0.52-x64.msi ............. Done
Downloading microsoft.net.sdk.tvos.manifest-7.0.100.msi.x64 (16.1.1481)
Installing Microsoft.NET.Sdk.tvOS.Manifest-7.0.100.16.1.1481-x64.msi ....... Done
Downloading Microsoft.NET.Runtime.WebAssembly.Sdk.Msi.x64 (7.0.1)
Installing Microsoft.WebAssembly.Sdk.7.0.1-x64.msi ....... Done
Downloading Microsoft.NETCore.App.Runtime.Mono.browser-wasm.Msi.x64 (7.0.1)
Installing Microsoft.Mono.browser-wasm.7.0.1-x64.msi ............ Done
Downloading Microsoft.NETCore.App.Runtime.AOT.win-x64.Cross.browser-wasm.Msi.x64 (7.0.1)
Installing Microsoft.AOT.win-x64.Cross.browser-wasm.7.0.1-x64.msi ...... Done
Downloading Microsoft.NET.Runtime.MonoAOTCompiler.Task.Msi.x64 (7.0.1)
Installing Microsoft.MonoAOTCompiler.Task.7.0.1-x64.msi ....... Done
Downloading Microsoft.NET.Runtime.MonoTargets.Sdk.Msi.x64 (7.0.1)
Installing Microsoft.MonoTargets.Sdk.7.0.1-x64.msi ...... Done
Downloading Microsoft.NET.Runtime.Emscripten.3.1.12.Node.win-x64.Msi.x64 (7.0.1)
Installing Microsoft.Emscripten.3.1.12.Node.win-x64.7.0.1-x64.msi ......... Done
Downloading Microsoft.NET.Runtime.Emscripten.3.1.12.Python.win-x64.Msi.x64 (7.0.1)
Installing Microsoft.Emscripten.3.1.12.Python.win-x64.7.0.1-x64.msi ...................... Done
Downloading Microsoft.NET.Runtime.Emscripten.3.1.12.Cache.win-x64.Msi.x64 (7.0.1)
Installing Microsoft.Emscripten.3.1.12.Cache.win-x64.7.0.1-x64.msi ....................... Done
Downloading Microsoft.NET.Runtime.Emscripten.3.1.12.Sdk.win-x64.Msi.x64 (7.0.1)
Workload installation failed. Rolling back installed packs...
Removing Microsoft.Emscripten.3.1.12.Cache.win-x64.7.0.1-x64.msi ............................... Done
Removing Microsoft.Emscripten.3.1.12.Python.win-x64.7.0.1-x64.msi ............................ Done
Removing Microsoft.Emscripten.3.1.12.Node.win-x64.7.0.1-x64.msi .... Done
Removing Microsoft.MonoTargets.Sdk.7.0.1-x64.msi ..... Done
Removing Microsoft.MonoAOTCompiler.Task.7.0.1-x64.msi ..... Done
Removing Microsoft.AOT.win-x64.Cross.browser-wasm.7.0.1-x64.msi ..... Done
Removing Microsoft.Mono.browser-wasm.7.0.1-x64.msi ......... Done
Removing Microsoft.WebAssembly.Sdk.7.0.1-x64.msi ..... Done
Downloading microsoft.net.sdk.tvos.manifest-7.0.100.msi.x64 (16.0.1478)
Downloading microsoft.net.sdk.maui.manifest-7.0.100.msi.x64 (7.0.49)
Dotnet : Workload installation failed: One or more errors occurred. (Downloading microsoft.net.runtime.emscripten.3.1.12.sdk.win-x64.msi.x64 version 7.0.1 failed)
At line:1 char:1
+ Dotnet workload install wasm-tools
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Workload instal...n 7.0.1 failed):String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Picture

0md85ypi

0md85ypi1#

我遇到了完全相同的错误与“你好世界”,“点击我”应用程序是默认的。它工作了几个星期,然后突然它将不再编译。得到了相同的错误。
经过几个星期的寻找,这终于解决了我:
在开发人员命令提示符中,我运行了:

dotnet workload install maui

这个持续了很长时间。
在它完成之后,我退出了VisualStudio,重新启动,重新加载了解决方案,但它仍然失败了。我给了它时间去做它似乎正在做的所有事情。
我退出VisualStudio更多的时间,重新启动,我现在正在编译。(我担心它会在某个时候再次停止)。

相关问题