Search code examples
c#msbuildpublish

Is it possible to create a website application publish profile from the command line?


I'd like to automate the procedure of publishing a new website application.

I'm using msbuild to build the project and I was wondering if it's possible to create a publish profile through the command line.

I've searched google for it but found only articles saying that it is created in VS.

Is that even possible?


Solution

  • As long as you can produce a working publish profile, you can specify it on command line using

    msbuild /p:DeployOnBuild=true /p:PublishProfile=C:\full\path\to\pub.xml 
    

    The publish profile itself is just an xml file so you can have a template in your CI scripts to do search & replace on.

    It also is just an msbuild project file so you can theoretically use msbuild libraries to create/modify one. I went as far as to generate a publish profile from an msbuild script called using

    msbuild ci-publish.proj
    

    Link: https://gist.github.com/dasMulli/625f3ad8c1b49748bb7f6ad8a230bf76#file-ci-publish-proj-xml-L56-L66 (the important part is lines 54-77 where a publish profile with pre-filled values is written to disk and an msbuild invocation is made).