Skip to content

Commit 37e6654

Browse files
committed
#4093 - allow to override the TargetFramework
1 parent d5d9033 commit 37e6654

File tree

3 files changed

+18
-37
lines changed

3 files changed

+18
-37
lines changed

docs/input/docs/usage/msbuild.md

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ If you're using `PackageReference` style NuGet dependencies (VS 2017+), add
3636
dependency of your package:
3737

3838
```xml
39-
<PackageReference Include="GitVersion.MsBuild" Version="5.12.0">
39+
<PackageReference Include="GitVersion.MsBuild" Version="6.0.0">
4040
<PrivateAssets>All</PrivateAssets>
4141
</PackageReference>
4242
```
@@ -47,39 +47,6 @@ The next thing you need to do is to remove the `Assembly*Version` attributes fro
4747
your `Properties\AssemblyInfo.cs` files. This puts GitVersion.MsBuild in charge of
4848
versioning your assemblies.
4949

50-
### WPF specific concerns
51-
52-
One further step needs to be taken for SDK-style WPF projects.
53-
54-
Building projects with .NET Core SDK with a version lower than v5.0.200
55-
requires turning off automatic generation of the different versioning attributes.
56-
GitVersion usually controls these properties but cannot during WPF specific
57-
targets that generate a temporary project.
58-
59-
```xml
60-
<PropertyGroup>
61-
<!-- Wpf workaround: GitVersion and .NET SDK < v5.0.200 -->
62-
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
63-
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
64-
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
65-
</PropertyGroup>
66-
```
67-
68-
For .NET Core SDK v5.0.200 to v6.0.0-preview.1, a opt-in flag was introduced to
69-
allow package references to be imported to the temporary project.
70-
You can now remove the previous versioning attributes and replace them with
71-
a single property.
72-
73-
```xml
74-
<PropertyGroup>
75-
<!-- WPF workaround: GitVersion and .NET SDK between v5.0.200 and v6.0.0-preview.2 -->
76-
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
77-
</PropertyGroup>
78-
```
79-
80-
You can remove all workarounds if you are building with .NET Core SDK
81-
v6.0.0-preview.2 or later as the flag is now opt-out.
82-
8350
### Done!
8451

8552
The setup process is now complete and GitVersion.MsBuild should be working its magic,
@@ -260,6 +227,18 @@ For SDK-style projects, `UpdateVersionProperties` controls setting the default
260227
variables: `Version`, `VersionPrefix`, `VersionSuffix`, `PackageVersion`,
261228
`InformationalVersion`, `AssemblyVersion` and `FileVersion`.
262229

230+
## Overriding Target Framework
231+
232+
If you want to override the target framework that GitVersion uses to determine the version, you can set the `GitVersionTargetFramework` property in your MSBuild script, like this:
233+
234+
```xml
235+
<PropertyGroup>
236+
...
237+
<GitVersionTargetFramework>net8.0-android</GitVersionTargetFramework>
238+
...
239+
</PropertyGroup>
240+
```
241+
263242
### Namespace generation
264243

265244
You can configure GitVersion to generate the `GitVersionInformation` class in a namespace that matches the current assembly. By default this class is created in the global namespace. If `UseProjectNamespaceForGitVersionInformation` is set to true, the `GitVersionInfomation` class will instead be generated in a namespace matching the current project. If the property `<RootNamespace>` is set that value will be used, otherwise the name of the project file is used.

src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
<GitVersion_ToolArgments Condition=" '$(GitVersion_NoFetchEnabled)' == 'true' ">$(GitVersion_ToolArgments) -nofetch</GitVersion_ToolArgments>
1717
<GitVersion_ToolArgments Condition=" '$(GitVersion_NoNormalizeEnabled)' == 'true' ">$(GitVersion_ToolArgments) -nonormalize</GitVersion_ToolArgments>
1818
<GitVersion_ToolArgments Condition=" '$(GitVersion_NoCacheEnabled)' == 'true' ">$(GitVersion_ToolArgments) -nocache</GitVersion_ToolArgments>
19+
20+
<GitVersionTargetFramework Condition="'$(GitVersionTargetFramework)' == ''">$(TargetFramework)</GitVersionTargetFramework>
21+
22+
<GitVersionFileExe Condition="'$(GitVersionFileExe)' == ''">dotnet --roll-forward Major &quot;$([MSBuild]::EnsureTrailingSlash($(MSBuildThisFileDirectory)$(GitVersionTargetFramework)))gitversion.dll&quot;</GitVersionFileExe>
23+
<GitVersionAssemblyFile Condition="'$(GitVersionAssemblyFile)' == ''">$([MSBuild]::EnsureTrailingSlash($(MSBuildThisFileDirectory)$(GitVersionTargetFramework)))GitVersion.MsBuild.dll</GitVersionAssemblyFile>
1924
</PropertyGroup>
2025

2126
<PropertyGroup>

src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.targets

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
<UpdateAssemblyInfo Condition=" '$(UpdateAssemblyInfo)' == 'true' And '$(GenerateGitVersionFiles)' == 'true' ">true</UpdateAssemblyInfo>
99
<GenerateGitVersionInformation Condition=" '$(GenerateGitVersionInformation)' == '' And '$(GenerateGitVersionFiles)' == 'true' ">true</GenerateGitVersionInformation>
10-
11-
<GitVersionFileExe Condition="'$(GitVersionFileExe)' == ''">dotnet --roll-forward Major &quot;$([MSBuild]::EnsureTrailingSlash($(MSBuildThisFileDirectory)$(TargetFramework)))gitversion.dll&quot;</GitVersionFileExe>
12-
<GitVersionAssemblyFile Condition="'$(GitVersionAssemblyFile)' == ''">$([MSBuild]::EnsureTrailingSlash($(MSBuildThisFileDirectory)$(TargetFramework)))GitVersion.MsBuild.dll</GitVersionAssemblyFile>
1310
</PropertyGroup>
1411

1512
<UsingTask TaskName="GetVersion" AssemblyFile="$(GitVersionAssemblyFile)" />

0 commit comments

Comments
 (0)