2

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?

PerryC
  • 1,233
  • 2
  • 12
  • 28
Mark Tomlinson
  • 117
  • 1
  • 11

2 Answers2

4

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)

KMoraz
  • 14,004
  • 3
  • 49
  • 82
2

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

Community
  • 1
  • 1
PerryC
  • 1,233
  • 2
  • 12
  • 28
  • Marked as answer while the other was first this is more in depth and the second link to "macros for build commands and properties" led me to what i needed! Interesting that $(SolutionDir) its inconsistent in a property group which is the way i'm using it. I will see if $(MSBuildProjectDirectory) holds up and the build doesn't remove it. – Mark Tomlinson Jan 21 '16 at 23:40