How to “get rid of” $(SolutionDir) when building Visual Studio project from outside Visual Studio

后端 未结 3 1638
粉色の甜心
粉色の甜心 2021-02-04 00:28

I want to build a .vcxproj via MSBuild from outside Visual Studio. The problem is that there are many occurrences of $(SolutionDir) inside the .vcxproj file which apparently onl

3条回答
  •  渐次进展
    2021-02-04 01:26

    The solution to explicitly pass SolutionDir as an argument is insufficient for me.

    Namely, if the project I want to build has dependencies with different build configurations, the build fails with a This project doesn't contain the Configuration and Platform combination of error.

    This makes sense, since I didn't specify the target configuration for the dependencies and thus it tries to target same configuration as the project I'm building, which they don't have (in my case).

    Since a solution file contains the build configurations for all projects in the solution (given some solution-configuration), we want to make use of this solution to solve this problem. Luckily, MSBuild allows us to build a solution and pass a specific target project as argument, which will only cause that project to be build (together with its dependencies).

    msbuild MySolution.sln /t:MyProject
    

提交回复
热议问题