Search code examples
c#.net-corecommand-line-interfacedotnet-clidotnet-sdk

Can .NET CORE CLI - load arguments from file?


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!


Solution

  • 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.