Update MSBuild tips

James Groom 2024-04-04 06:15:35 +10:00
parent b5e15c26d8
commit c596099728
1 changed files with 6 additions and 4 deletions

@ -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 `<PropertyGroup/>`.
On (older versions of?) VS, `Condition` is ignored if placed on a property/item. Create a new `<PropertyGroup/>`/`<ItemGroup/>`.
## MSBuild property evaluation execution order
## MSBuild path properties
When `<Import/>`ing a `.props` file, `ProjectDir` is unset <!-- TODO only during property evaluation? --> (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 `<Import/>`ing a `.props` file, `$(ProjectDir)` is unset. <!-- TODO only during property evaluation? -->
(`$(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