Search code examples
.netcommand-linemsbuildmsbuild-4.0

Passing msbuild Parameter in Build.proj


I am building a dotnet project via this command line:

${msbuild} /m /t:Rebuild;Package /p:Configuration=Release /p:OutputPath=${WORKSPACE}/target build.proj

What I intend to do is pass all parameter flags in build.proj and then msbuild to get them during build time. Is that even possible and how?

Intention:

${msbuild}  build.proj

and the parameters:

/m /t:Rebuild;Package /p:Configuration=Release /p:OutputPath=${WORKSPACE}/target

will go in build.proj


Solution

  • Sure! Since you want to include moving the /m from the command line into build.proj, you will need to use the MSBuild task in build.proj. (So, yes, the msbuild.exe process that you create from the command line will in turn execute another msbuild.exe process.)

    <MSBuild
        Projects="PATH TO PROJECT FILE"
        Targets="Rebuild;Package"
        BuildInParallel="true"
        Properties="Configuration=Release;OutputPath=PATH TO OUTPUT FOLDER">
    </MSBuild>
    

    By the way, as long as the Target element that you wrap that task in is the only Target in build.proj, your ${msbuild} build.proj command line will execute that Target regardless of the value you put in its Name attribute.