在将我的应用程序从netcoreapp3.1升级到net6.0之后,尝试通过命令行发布我的应用程序时,我得到了下面的错误:
dotnet cake build/build.cake --target=Publish --Verbosity=Diagnostic --runtimeIdentifier=win-x64
结果:
C:\ProgramFiles\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(898,5): error MSB4018: The "GenerateBundle" task failed unexpectedly. [C:\FolderHost\ProjectFileHost.csproj]
C:\ProgramFiles\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(898,5): error MSB4018: System.IO.FileNotFoundException: Could not find file 'C:\FolderHost\obj\Release\net6.0\win-x64\singlefilehost.exe'. [C:\FolderHost\ProjectFileHost.csproj]
C:\ProgramFiles\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(898,5): error MSB4018: File name: 'C:\FolderHost\obj\Release\net6.0\win-x64\singlefilehost.exe' [C:\\FolderHost\ProjectFileHost.csproj]
C:\ProgramFiles\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(898,5): error MSB4018: at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [C:\FolderHost\ProjectFileHost.csproj]
C:\ProgramFiles\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(898,5): error MSB4018: at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite) [C:\FolderHost\ProjectFileHost.csproj]
C:\ProgramFiles\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(898,5): error MSB4018: at Microsoft.NET.HostModel.AppHost.BinaryUtils.CopyFile(String sourcePath, String destinationPath) [C:\FolderHost\ProjectFileHost.csproj]
C:\ProgramFiles\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(898,5): error MSB4018: at Microsoft.NET.HostModel.Bundle.Bundler.GenerateBundle(IReadOnlyList`1 fileSpecs) [C:\FolderHost\ProjectFileHost.csproj]
C:\ProgramFiles\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(898,5): error MSB4018: at Microsoft.NET.Build.Tasks.GenerateBundle.ExecuteCore() [C:\FolderHost\ProjectFileHost.csproj]
C:\ProgramFiles\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(898,5): error MSB4018: at Microsoft.NET.Build.Tasks.TaskBase.Execute() [C:\FolderHost\ProjectFileHost.csproj]
C:\ProgramFiles\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(898,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\FolderHost\ProjectFileHost.csproj]
C:\ProgramFiles\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(898,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\FolderHost\ProjectFileHost.csproj]
An error occurred when executing task 'Publish'.
Error: .NET CLI: Process returned an error (exit code 1).ProjectFileHost.csproj财产组:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<AssemblyName>xxxxx.xxxx.xxxxxx</AssemblyName>
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
</PropertyGroup>PublishArtifacts代码( operations.cake ):
void PublishArtifact(string projPath, string runtime, string artfDir)
{
DotNetCorePublishSettings pub = new DotNetCorePublishSettings()
{
Framework = "net6.0",
Runtime = runtime,
PublishSingleFile = true,
Configuration = "Release",
NoBuild = true,
NoRestore = true,
OutputDir = artfDir + "/" + runtime
};
DotNetCorePublish(projPath, pub);
}如果我们创建PublishSingleFile = false,那么发布命令将在工件中运行并创建应用程序和dll文件。但是我们需要在一个.exe文件中发布这个应用程序。任何帮助都将不胜感激。
发布于 2022-07-20 12:50:03
这不是蛋糕错误,而是msbuild错误。不存在要部署的文件C:\FolderHost\obj\Release\net6.0\win-x64\singlefilehost.exe。
我的猜测是,由于您已经在您的NoBuild = true中设置了DotNetCorePublishSettings,所以项目没有预先构建(在所需的配置中)。
您可以设置NoBuild = false, NoRestore = false,也可以在发布之前运行DotNet[Core]Build()。
另外,请注意,DotNetCore***别名已被废弃,以支持新的DotNet***别名蛋糕2.0.0。
发布于 2022-08-17 08:28:53
将PublishSingleFile设置为true在ProjectFileHost.csproj属性组中创建了singlefilehost.exe
<PublishSingleFile>true</PublishSingleFile>https://stackoverflow.com/questions/73051676
复制相似问题