4

I am trying to use $(SolutionDir) or $(SolutionPath) in a .csproj file in Visual Studio 2017 but they do not work as expected.

In an MSBuild 15 type project (e.g., .NET Core, .NET Standard class library), using $(SolutionDir) in a <PostBuildEvent> works, but $(ProjectDir) just produces an empty string.

In other elements (e.g., AssemblyFile in UsingTask) $(SolutionDir) produces an empty string and $(SolutionPath) gives me the current project directory.

This has been reported to Microsoft at https://developercommunity.visualstudio.com/content/problem/11118/postbuild-event-and-macros-issues.html but the issue has been marked as Closed on the grounds that the problem was fixed in RTM, even though several people have reported having problems with the released version.

Ian Griffiths
  • 14,302
  • 2
  • 64
  • 88
VGeorgiev
  • 103
  • 1
  • 9
  • this seems to be an issue with VS2017, https://developercommunity.visualstudio.com/content/problem/3940/solutiondir-macro-at-pre-build-event-gives-undefin.html, you may need Visual Studio 2017 RC 3. – Anil Apr 25 '17 at 12:02
  • I am not with release candidate. I am with VS 15.1 (26403.3) from 10 April 2017. – VGeorgiev Apr 25 '17 at 12:14
  • It is not working even with the latest release 15.1 (26403.07) from April 17, 2017 – VGeorgiev Apr 25 '17 at 12:37
  • 1
    Where exactly are you using it? inside a custom target with an `` task. Classic csproj or "sdk-style" (usually .net core) csproj? – Martin Ullrich Apr 25 '17 at 12:54
  • I realize that If I am using the $(SolutionDir) for some command in PostBuildEvent for example it is working okay, but if I try to use it in a value of some property (AssemblyFile in UsingTask for example) is not working. @MartinUllrich .net core csproj. – VGeorgiev Apr 25 '17 at 13:04
  • Does it work on `dotnet build the.sln` or are those properties just wrong inside VS? this may have to do with the new project system for .net core csproj files.. – Martin Ullrich Apr 25 '17 at 13:09
  • Seems like you declared it before the macro / property was initialised. Try `$(MSBuildProjectDir)` instead. ProjectDir is set after a specific import (eg Microsoft.Common.Targets), while MSBuildProjectDir is a MSBuild reserved macro, and should be available unless you aren't building with MSBuild. > http://stackoverflow.com/questions/32435599/solutiondir-msbuild-property-incorrect-when-running-sandcastle-help-file-buil < for an alternative to SolutionDir – Biepbot Von Stirling May 09 '17 at 19:27

0 Answers0