From c596099728e645ac0d9487397da0bb0652e5c13f Mon Sep 17 00:00:00 2001 From: James Groom Date: Thu, 4 Apr 2024 06:15:35 +1000 Subject: [PATCH] Update MSBuild tips --- C#-and-.NET-docs-supplement.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/C#-and-.NET-docs-supplement.md b/C#-and-.NET-docs-supplement.md index 4b385c8..0beff3c 100644 --- a/C#-and-.NET-docs-supplement.md +++ b/C#-and-.NET-docs-supplement.md @@ -31,12 +31,14 @@ You can only have 1 `default` branch, but `case _ when ...:` doesn't work. Howev ## MSBuild `Condition` placement -On (older versions of?) VS, `Condition` is ignored if placed on a property/item. Create a new ``. +On (older versions of?) VS, `Condition` is ignored if placed on a property/item. Create a new ``/``. -## MSBuild property evaluation execution order +## MSBuild path properties -When ``ing a `.props` file, `ProjectDir` is unset (but `SolutionDir` *is* set, if applicable). -Use `MSBuildProjectDirectory`. Note that the latter doesn't include a trailing slash. +Always use `$(MSBuildProjectDirectory)` rather than `$(ProjectDir)` (note that the former doesn't include a trailing slash), because when ``ing a `.props` file, `$(ProjectDir)` is unset. +(`$(SolutionDir)` *is* set, but that should be avoided even in the main solution.) + +Use `$(TargetPath)` rather than reconstructing e.g. `$(OutputPath)$(MSBuildProjectName).dll`. ## `Newtonsoft.Json` footguns