Skip to content

Commit 6e443ae

Browse files
jbaehrarturcic
authored andcommitted
Prevent GenerateGitVersionInformation in XAML generated projects
During XAML'S build magic a temporary project may get generated and build (target "GenerateTemporaryTargetAssembly"). The generated project file already contains compile-items with the generated files from the original project, this `GitVerstionInformation.g.cs` is listed. When the GitVersion task now runs again, the file is added another time resulting in an error of CSC. This patch tries to detect this situation and prevent the execution of GenerateGitVersionInformation by checking for a special property injected by GenerateTemporaryTargetAssembly. Unfortunately this is not documented and thus may change. See also - https://referencesource.microsoft.com/#PresentationBuildTasks/BuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs,163 - #2228
1 parent ab59830 commit 6e443ae

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/GitVersionTask/build/GitVersionTask.props

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424

2525
<!-- Property that enables GenerateGitVersionInformation -->
2626
<GenerateGitVersionInformation Condition=" '$(DisableGitVersionTask)' == 'true' ">false</GenerateGitVersionInformation>
27+
<!--
28+
During XAML's "GenerateTemporaryTargetAssembly" a new project file is generated and compiled
29+
which already contains the "GeneratedCodeFiles", i.e. GitVersionInformation.g.cs.
30+
Then, when GenerateGitVersionInformation is called in this temp-build, the file is added another time, which results in an error at CSC.
31+
Here we try to detect this situation and prevent GenerateGitVersionInformation from running.
32+
(The global property "_TargetAssemblyProjectName" is injected by XAML's above-mentioned task)
33+
-->
34+
<GenerateGitVersionInformation Condition=" '$(GenerateGitVersionInformation)' == '' And '$(_TargetAssemblyProjectName)' != '' ">false</GenerateGitVersionInformation>
2735
<GenerateGitVersionInformation Condition=" '$(GenerateGitVersionInformation)' == '' ">true</GenerateGitVersionInformation>
2836

2937
<!-- Property that enables GetVersion -->

0 commit comments

Comments
 (0)