Reputation: 15159
My .csproj
file contains this declaration:
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
...
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
</PropertyGroup>
My expectation was it needed to discover the solution file when you build the project directly from the project directory and don't specify /p:SolutionDir=
parameter. However, ..\
is not automatically resolved to an absolute path and so is useless if you have solution related dependencies.
Upvotes: 4
Views: 4899
Reputation: 100581
It looks like this was added to your project file to allow building the csproj file independent of the solution file, by setting the SolutionDir
property if it isn't set to a correct value already (which would be the case if you'd call msbuild my.sln
but not when executing msbuild my.csproj
).
I'm assuming some other build logic in your csproj file (or imported props/targets file) uses $(SolutionDir)
somewhere, so it would fail if the property wasn't set using this conditional declaration.
MSBuild interprets paths relative to the csproj file and executes all commands by setting the working directory to the location of the csproj file so ..\
should work in almost all use cases.
Upvotes: 5