MSBuild solution command line output to individual folders

后端 未结 1 936
情话喂你
情话喂你 2021-01-18 00:04

Currently, I have the following MSBuild command:

msbuild 
    /t:Build 
    /p:Configuration=Release 
    /p:OutputPath=C:\\MySolutionOutput\\ 
    MySolutio         


        
1条回答
  •  情歌与酒
    2021-01-18 00:37

    When building a solution using msbuild, it internally transforms the solution into an msbuild xml file which builds all projects and passes properties like OutputPath to it, and afaik there isn't a way to interfere with how this behaves. One possible solution does require you to write msbuild files yourself, but the modifications are really minor. You don't mention which project type you're using but the principle is the same for any type, and here's a sample for C# projects:

    • create a common file which allows overriding OutputPath in the way you want it, but does nothing unless specifically told to in order to keep existing behaviour if needed
    • import that file in each project
    • specify custom output directory on the command line

    msbuild file, say outputpath.props:

    
    
      
        $(OutputPathBaseDir)\$(MSBuildProjectName)\
      
    
    

    import in each project; here I am using a relative path but you could reference eg $(SolutionDir) etc; for c# projects, insert this line right before the one shown

    
    
    
    

    now build:

    msbuild mysolution.sln /p:OutputPathBaseDir=C:\MySolutionOutput
    

    0 讨论(0)
提交回复
热议问题