You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My Cake script has separate steps for building my C# console app and publishing the app to a single file. These Cake tasks are very simple and they look like this:
Error: Cake.Core.CakeException: .NET CLI: Process returned an error (exit code 1).
at Cake.Core.Tooling.Tool`1.ProcessExitCode(Int32 exitCode) in C:\projects\cake\src\Cake.Core\Tooling\Tool.cs:line 118
at Cake.Core.Tooling.Tool`1.Run(TSettings settings, ProcessArgumentBuilder arguments, ProcessSettings processSettings, Action`1 postAction) in C:\projects\cake\src\Cake.Core\Tooling\Tool.cs:line 103
at Cake.Common.Tools.DotNet.DotNetTool`1.RunCommand(TSettings settings, ProcessArgumentBuilder arguments) in C:\projects\cake\src\Cake.Common\Tools\DotNet\DotNetTool.cs:line 64
at Cake.Common.Tools.DotNet.Publish.DotNetPublisher.Publish(String path, DotNetPublishSettings settings) in C:\projects\cake\src\Cake.Common\Tools\DotNet\Publish\DotNetPublisher.cs:line 48
at Cake.Common.Tools.DotNet.DotNetAliases.DotNetPublish(ICakeContext context, String project, DotNetPublishSettings settings) in C:\projects\cake\src\Cake.Common\Tools\DotNet\DotNetAliases.cs:line 339
at Submission#0.DotNetPublish(String project, DotNetPublishSettings settings)
at Submission#0.<<Initialize>>b__0_7()
at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass36_0.<Does>b__0(ICakeContext _) in C:\projects\cake\src\Cake.Core\CakeTaskBuilder.Execution.cs:line 26
at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass39_0.<Does>b__0(ICakeContext context) in C:\projects\cake\src\Cake.Core\CakeTaskBuilder.Execution.cs:line 81
at Cake.Core.CakeTask.Execute(ICakeContext context) in C:\projects\cake\src\Cake.Core\CakeTask.cs:line 119
at Cake.Core.DefaultExecutionStrategy.ExecuteAsync(CakeTask task, ICakeContext context) in C:\projects\cake\src\Cake.Core\DefaultExecutionStrategy.cs:line 69
at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 318
at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 341
at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 353
at Cake.Core.CakeEngine.RunTask(ICakeContext context, IExecutionStrategy strategy, CakeTask task, String target, Stopwatch stopWatch, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 254
at Cake.Core.CakeEngine.RunTarget(ICakeContext context, IExecutionStrategy strategy, CakeTask[] orderedTasks, String target, Boolean exclusive, Stopwatch stopWatch, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 229
at Cake.Core.CakeEngine.RunTargetAsync(ICakeContext context, IExecutionStrategy strategy, ExecutionSettings settings) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 199
at Cake.Cli.BuildScriptHost`1.internalRunTargetAsync() in C:\projects\cake\src\Cake.Cli\Hosts\BuildScriptHost.cs:line 87
at Cake.Cli.BuildScriptHost`1.RunTargetAsync(String target) in C:\projects\cake\src\Cake.Cli\Hosts\BuildScriptHost.cs:line 74
at Cake.Core.Scripting.ScriptHost.RunTarget(String target) in C:\projects\cake\src\Cake.Core\Scripting\ScriptHost.cs:line 110
at Submission#0.<<Initialize>>d__0.MoveNext()
--- End of stack trace from previous location ---
at Cake.Infrastructure.Scripting.RoslynScriptSession.RunScriptAssembly(String assemblyPath) in C:\projects\cake\src\Cake\Infrastructure\Scripting\RoslynScriptSession.cs:line 225
at Cake.Infrastructure.Scripting.RoslynScriptSession.Execute(Script script) in C:\projects\cake\src\Cake\Infrastructure\Scripting\RoslynScriptSession.cs:line 201
at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath) in C:\projects\cake\src\Cake.Core\Scripting\ScriptRunner.cs:line 172
at Cake.Features.Building.BuildFeature.RunCore(ICakeArguments arguments, BuildFeatureSettings settings) in C:\projects\cake\src\Cake\Features\Building\BuildFeature.cs:line 99
at Cake.Features.Building.BuildFeature.Run(ICakeArguments arguments, BuildFeatureSettings settings) in C:\projects\cake\src\Cake\Features\Building\BuildFeature.cs:line 49
at Cake.Commands.DefaultCommand.Execute(CommandContext context, DefaultCommandSettings settings) in C:\projects\cake\src\Cake\Commands\DefaultCommand.cs:line 76
This problem seems to be exactly the same described in this SO question.
I am using .NET SDK 8, my app is targeting .NET8 and I am using Cake 4.0.0. However, the person who reported the problem in the SO question I linked above used a different SDK and different version of Cake which leads me to believe this problem is not specific to a version of .NET or a specific version of Cake.
This seems to be a problem with dotnet more so than Cake, but I am reporting it here and offering a few workarounds in case it can be helpful to others. After a lot of trial and errors, I came to the realization that the issue is the "build" task is not aware that the app will ultimately be published as a single file and therefore doesn't build my app in a way that is expected by the "publish" task.
I came up with two possible workarounds:
You can combine the "build" and "publish" tasks into a single task that invokes DotNetPublish like so (notice "NoBuild=false"):
You can preserve the separate tasks but instead of specifying "PublishSingleFile=true" and "SelfContained=true" in the Cake script, you move these settings to your .csproj by adding the following two lines:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
My Cake script has separate steps for building my C# console app and publishing the app to a single file. These Cake tasks are very simple and they look like this:
The build task:
and the publish task (notice that I am publishing to a single file):
Invoking my Cake script results in an unhelpful error message from dotnet:
followed by an exception from Cake:
This problem seems to be exactly the same described in this SO question.
I am using .NET SDK 8, my app is targeting .NET8 and I am using Cake 4.0.0. However, the person who reported the problem in the SO question I linked above used a different SDK and different version of Cake which leads me to believe this problem is not specific to a version of .NET or a specific version of Cake.
This seems to be a problem with dotnet more so than Cake, but I am reporting it here and offering a few workarounds in case it can be helpful to others. After a lot of trial and errors, I came to the realization that the issue is the "build" task is not aware that the app will ultimately be published as a single file and therefore doesn't build my app in a way that is expected by the "publish" task.
I came up with two possible workarounds:
.csproj
by adding the following two lines:In either case, the result is that the build/publish tasks will play nice with each other and your app will be published as a single app.
I hope this is helpful to someone.
Beta Was this translation helpful? Give feedback.
All reactions