Mark Tomlinson
Mark Tomlinson

Reputation: 127

Visual Studio Publish MSdeploy $(SolutionDir)

I'm having an annoying issue with MSDeploy and Visual Studio's publish profile. In my project I have a property group that I setup an item to reference later.

<LocalBuildLocation>$(SolutionDir)WebSites\MyWebSite\</LocalBuildLocation>

Unfortunately, Visual Studio will randomly drop the $(SolutionDir) string from this property and my build will fail. I copy it back in manually and everything is good to go.

Can anyone think of why this item keeps removing itself?

Upvotes: 2

Views: 1658

Answers (2)

PerryC
PerryC

Reputation: 1291

See: $(SolutionDir) MSBuild property incorrect when running Sandcastle Help File Builder via CMD and getting the value of $(ProjectDir), $(SolutionDir) in a vcproj file

It looks like $SolutionDir does (sometimes) work with MSBuild, but only if you're building from the solution file. It is the same thing as $ProjectDir for the most part.

But you're not supposed to be able to use them in MSBuild. Even though they work sometimes -- it's not reliable. And as pointed out by the other answer:

Visual Studio macros like $(SolutionDir) don’t work in MSBuild. You can use project properties instead.

Source: Code Generation in a Build Process

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

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

Note that:

You can use these macros anywhere in a project's Property Pages dialog box where strings are accepted.

Source: Macros for Build Commands and Properties

Upvotes: 2

KMoraz
KMoraz

Reputation: 14164

From MSDN: Using project properties in assembly and include directives

Visual Studio macros like $(SolutionDir) don’t work in MSBuild. You can use project properties instead.

Use $(ProjectDir) (safer, project level property) or $(MSBuildProjectDirectory) (safest, always exist)

Upvotes: 4

Related Questions