Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prebuild event in Visual Studio replacing $(SolutionDir) with *Undefined*

I believe the problem is documented here moved here and looks like it might be a bug in visual studio, but I'm wondering if anyone knows of a workaround.

Basically I have the following two lines (among other things) one right after the other in the prebuild event.

"C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe" /p:configuration=Release;platform=x86 /t:rebuild "$(SolutionDir)Folder1\Project1.csproj"

"C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe" /p:configuration=Release;platform=x86 /t:rebuild "$(SolutionDir)Folder2\Folder3\Project2.csproj" 

The first one succeeds and the other fails saying that The command ""C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe" /p:configuration=Release;platform=x86 /t:rebuild "*Undefined*Folder2\Folder3\Project2.csproj"" exited with code 1..

Edit:
Figured out the problem was that one of the other projects with the same line as it's prebuild failed, since MSBuild itself doesn't know about the macros.

like image 910
Davy8 Avatar asked Mar 11 '09 16:03

Davy8


2 Answers

I fixed this by replacing all $(SolutionDir) with $(ProjectDir)..\.

It was due to MSBuild running each project independently, and thus not the solution. It worked fine in VS2010, but not on the build server.

like image 55
Allan Kimmer Jensen Avatar answered Oct 15 '22 16:10

Allan Kimmer Jensen


Wasted a lot of time to find perfect solution for this problem. Use Directory.Build.props.

In your sln location folder create a file with name Directory.Build.props and put this code inside:

<Project>
 <PropertyGroup>
    <SolutionDir>$(MSBuildThisFileDirectory)</SolutionDir>
 </PropertyGroup>
</Project>

This file will be automagically picked up by all your csproj files and will define (SolutionDir) property.

like image 22
Artur Avatar answered Oct 15 '22 16:10

Artur