Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$(SolutionDir) MSBuild property incorrect when running Sandcastle Help File Builder via CMD

When I run the Sandcastle Help File Builder project file (for example, myproject.shfbproj) using Windows CMD, I get an annoying issue: $(SolutionDir) has the same value as $(ProjectDir), and this means that project documentation sources won't build correctly, because I'm adding custom targets which already use $(SolutionDir).

If I build the whole Sandcastle Help File Builder from Visual Studio it builds successfully.

I'm using the following command (executed from the directory where the project is stored):

"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /p:Configuration=Development myproject.shfbproj

Is there a workaround for this?

like image 330
Matías Fidemraizer Avatar asked Sep 07 '15 09:09

Matías Fidemraizer


People also ask

How use MSBuild command line?

To run MSBuild at a command prompt, pass a project file to MSBuild.exe, together with the appropriate command-line options. Command-line options let you set properties, execute specific targets, and set other options that control the build process.

How do I set MSBuild properties?

MSBuild lets you set properties on the command line by using the -property (or -p) switch. These global property values override property values that are set in the project file. This includes environment properties, but does not include reserved properties, which cannot be changed.

What is $( SolutionDir?

$(SolutionDir)The directory of the solution (defined as drive + path); includes the trailing backslash '\'.


2 Answers

You only get the the correct $(SolutionDir) if you're building your solution (.sln file). The .shfbproj is a project file, and as such has no reference to its parent solution. You can try specifying the $(SolutionDir) in your command line explicitly:

msbuild /p:Configuration=Development /p:SolutionDir=MySolutionDir myproject.shfbproj

For reference: $(SolutionDir) and MSBuild

like image 190
m0sa Avatar answered Oct 11 '22 09:10

m0sa


While @m0sa has pointed out a very obvious fact (since I'm building the Sandcastle Help File Builder project, there's no actual solution directory), the issue was also happening during a TFS Build when building the solution where the so-called documentation project resides.

For now I've managed to solve the issue using a nasty workaround: adding a SolutionDir property in each C# project that needs to be built as part of documentation project:

  <PropertyGroup>
    <SolutionDir>$([System.IO.Path]::GetDirectoryName($(MSBuildProjectDirectory)))\</SolutionDir>
  </PropertyGroup>

Since my solution file will always be located in the parent directory of Sandcastle Help File Builder project directory, in my case this workaround works...

Now referenced projects as documentation sources are able to import a custom project where I define common MSBuild properties, both in Visual Studio builds or external ones:

<Import Project="$(SolutionDir)MSBuild\Common.properties" />
like image 33
Matías Fidemraizer Avatar answered Oct 11 '22 10:10

Matías Fidemraizer