Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DotNetPublishSettings lacks some arguments #1350

Open
ArwynFr opened this issue Mar 15, 2024 · 4 comments · May be fixed by #1354
Open

DotNetPublishSettings lacks some arguments #1350

ArwynFr opened this issue Mar 15, 2024 · 4 comments · May be fixed by #1354
Labels

Comments

@ArwynFr
Copy link

ArwynFr commented Mar 15, 2024

Usage Information

NUKE version 8.0.0 / SDK version 8.0.200 / net 8.0 / Win 10 21H2 LTSC

Description

Some arguments of the dotnet publish command are missing from the fluent API, especially --os and --arch. Also you can't provide a custom build target. This feature is especially missing when using dotnet publish to push a docker image to a registry.

These options are probably missing on other commands such as pack/build.

Sources:
https://learn.microsoft.com/en-us/dotnet/core/docker/publish-as-container?pivots=dotnet-8-0#publish-net-app
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish

Reproduction Steps

DotNetTasks.DotNetPublish(_ => _
  .SetProject("project")
  .SetConfiguration(Configuration)
  .AddProperty("ContainerImageTag", OctoVersionInfo.FullSemVer)
  .SetOS("linux")
  .SetArch("x64")
  .SetTarget("PublishContainer"));

Expected Behavior

dotnet publish project --configuration Debug /p:ContainerImageTag=0.1.16 --os linux --arch x64 /t:PublishContainer

Actual Behavior

Compilation error

Regression?

No

Known Workarounds

DotNetTasks.DotNetPublish(_ => _
  .SetProject("project")
  .SetConfiguration(Configuration)
  .AddProperty("ContainerImageTag", OctoVersionInfo.FullSemVer)
  .SetProcessArgumentConfigurator(_ => _
    .Add("/t:PublishContainer")
    .Add("--os linux")
    .Add("--arch x64")));

Could you help with a pull-request?

No

@ArwynFr ArwynFr added the bug label Mar 15, 2024
@ITaluone ITaluone linked a pull request Mar 22, 2024 that will close this issue
3 tasks
@ITaluone
Copy link
Contributor

ITaluone commented Mar 29, 2024

@ArwynFr Could you please share your csproj.. I do not understand the /t:.. parameter.. Does it call something specific in the csproj, or is this an SDK specific switch?

Edit: As of this documentation the only possibility is /t:PublishContainer: https://learn.microsoft.com/en-us/dotnet/core/docker/publish-as-container?pivots=dotnet-8-0

So, probably we just could make it paramterless, don't we?

@ArwynFr
Copy link
Author

ArwynFr commented Mar 29, 2024

@ITaluone I've made some further investigations.

Basically dotnet-cli is a wrapper around other MS tools, espacially msbuild.dll, which is a .NET5+ port of the old legacy MsBuild.exe. The /t: is originally an msbuild parameter that stands for "target". It works exacly like a nuke target and that's how the sdk knows it must restore nuget before building and build before publishing. Usually, the MsBuild target is set by the dotnet cli command. For instance, dotnet publish command translates to msbuild.dll -target:Publish and dotnet restore translates to msbuild.dll -target:Restore.

dotnet publish /t:PublishContainer allows to override the actual msbuild target that was implicitly placed by the usage of the dotnet publish command into a msbuild.dll -target:PublishContainer. This allows the msbuild to know it has to publish a docker image rather than a binary. For many reasons MS prefered this over a separate dotnet publishContainer command. This behavior can be showased by the fact that running dotnet restore /t:Publish is equivalent to dotnet publish.

My tests have shown that you can use three different syntax for this feature at the dotnet cli level:

  • /t:PublishContainer
  • -t:PublishContainer
  • --target:PublishContainer

The --target PublishContainer format is not supported.

What targets are available is very complex though. Some targets come directly from the framework (Restore, Build, Publish). Some targets depend on the Sdk used: Microsoft.NET.Sdk, Microsoft.NET.Sdk.Web, ... Some targets are added by nuget packages, espacially packages involved in testing for instance. Also, developpers can directly add custom target in their csproj. Parsing targets are probably gonna be a pain to do and are beyond the scope of nuke in my opinion.

I would say you have two valid options:

  • add a .SetMsbuildTarget(string target) to override msbuild target on all dotnet cli commands
  • add a .SetPublishContainer() or .SetPublishContainer(bool isContainer) specific to dotnet publish

@ITaluone
Copy link
Contributor

ITaluone commented Apr 2, 2024

I would go with both SetTarget(string value) and SetPublishContainer(), but @matkoch should decide..

@ArwynFr
Copy link
Author

ArwynFr commented May 23, 2024

Any update ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants