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!

10
  • 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? Commented Sep 28, 2018 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 stackoverflow.com/questions/1955505/… Commented Sep 28, 2018 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 Commented Sep 28, 2018 at 15:50
  • 1
    @IvanRuski sounds like you are looking for publishing profiles? Once you create a publishing profile you can pass it to dotnet publish as an MSBuild parameter with /p:p:PublishProfile=<ProfileName> Commented Sep 28, 2018 at 15:57
  • 1
    @IvanRuski VS also has tasks files but I haven't used them Commented Sep 28, 2018 at 16:06

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.