3

I am using .net cli 2.0.3 and I was wondering if it is possible to load my arguments from file i.e.

dotnet publish -args somefile

Where somefile will contain the arguments which the certain command accepts. For example, while publishing I want to have predefined path\project.csproj -c Release -o "outputpath"

I know that there isn't that kind of command in the sdk, but is there a way that I can achieve it ?

Best regards!

Ivan Ruski
  • 1,123
  • 1
  • 13
  • 19
  • Its always best to prefer the "Config way" i.e using the appsettings.json file for situations like this. Do you have a different kind of requirement? – Rakshith Murukannappa Sep 28 '18 at 15:28
  • you can write a script ps1 OR sh depending on your env. Which reads the file and then calls the dotnet cli. see this https://stackoverflow.com/questions/1955505/parsing-json-with-unix-tools – Parv Sharma Sep 28 '18 at 15:47
  • @RakshithSm this isn't a question about the *application's* configuration, it's about passing arguments to the CLI tools. A settings file can't handle multiple environments and containers by the way. There's no single "best" way, all options have their place – Panagiotis Kanavos Sep 28 '18 at 15:50
  • I want something like vscode task.json, but I don't know what is the utility that is parsing it and executing it. – Ivan Ruski Sep 28 '18 at 15:56
  • 1
    @IvanRuski sounds like you are looking for [publishing profiles](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/visual-studio-publish-profiles?view=aspnetcore-2.1&tabs=aspnetcore2x#publish-profiles)? Once you create a publishing profile you can pass it to `dotnet publish` as an MSBuild parameter with `/p:p:PublishProfile=` – Panagiotis Kanavos Sep 28 '18 at 15:57
  • @Panagiotis Kanavos, yes exactly. `dotnet publish -h` does not shows the information you've provided. Thanks, that answers my question :) – Ivan Ruski Sep 28 '18 at 16:03
  • @IvanRuski that's because it's an MSBuild feature, not a feature of `dotnet publish` – Panagiotis Kanavos Sep 28 '18 at 16:06
  • 1
    @IvanRuski VS also [has tasks files](https://learn.microsoft.com/en-us/visualstudio/ide/customize-build-and-debug-tasks-in-visual-studio?view=vs-2017) but I haven't used them – Panagiotis Kanavos Sep 28 '18 at 16:06
  • Thanks I will make use of both links – Ivan Ruski Sep 28 '18 at 16:11
  • all msbuild based CLI commands don't show all the options that msbuild allows for. one of them is response files, see my answer. you'd need to know a few of the CLI->MSbuild translations (e.g. `-r win-x64` => `-p:RuntimeIdentifier=win-x64` etc.) – Martin Ullrich Sep 29 '18 at 14:53

1 Answers1

5

While the CLI itself doesn't have a mechanism to load response files, it calls out to MSBuild which does support both specified response files and the following automatic response files:

  1. MSBuild.rsp next to the project / solution file to build
  2. Directory.Build.rsp in the hierarchy at or above the project / solution file to build

While you cannot specify CLI arguments, you can specify their equivalent MSBuild arguments.

For example you can create a release.rsp next to your solution file that specifies:

-p:Configuration=Release
-p:OutputPath=..\rel-out\
-p:PublishDir=..\pub-out\

Which you could use to call

dotnet publish test\project.csproj @release.rsp

If the same file was named Directory.Build.rsp, it would have been applied automatically. If would also have been applied autoamatically if it was named MSbuild.rsp and put it next to the csproj file.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217