Skip to content

#4093 - allow to override the TargetFramework #4111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 13 additions & 34 deletions docs/input/docs/usage/msbuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ If you're using `PackageReference` style NuGet dependencies (VS 2017+), add
dependency of your package:

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

### WPF specific concerns

One further step needs to be taken for SDK-style WPF projects.

Building projects with .NET Core SDK with a version lower than v5.0.200
requires turning off automatic generation of the different versioning attributes.
GitVersion usually controls these properties but cannot during WPF specific
targets that generate a temporary project.

```xml
<PropertyGroup>
<!-- Wpf workaround: GitVersion and .NET SDK < v5.0.200 -->
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
</PropertyGroup>
```

For .NET Core SDK v5.0.200 to v6.0.0-preview.1, a opt-in flag was introduced to
allow package references to be imported to the temporary project.
You can now remove the previous versioning attributes and replace them with
a single property.

```xml
<PropertyGroup>
<!-- WPF workaround: GitVersion and .NET SDK between v5.0.200 and v6.0.0-preview.2 -->
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
</PropertyGroup>
```

You can remove all workarounds if you are building with .NET Core SDK
v6.0.0-preview.2 or later as the flag is now opt-out.

### Done!

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

## Overriding Target Framework

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:

```xml
<PropertyGroup>
...
<GitVersionTargetFramework>net8.0</GitVersionTargetFramework>
...
</PropertyGroup>
```

### Namespace generation

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.
Expand Down
5 changes: 5 additions & 0 deletions src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<GitVersion_ToolArgments Condition=" '$(GitVersion_NoFetchEnabled)' == 'true' ">$(GitVersion_ToolArgments) -nofetch</GitVersion_ToolArgments>
<GitVersion_ToolArgments Condition=" '$(GitVersion_NoNormalizeEnabled)' == 'true' ">$(GitVersion_ToolArgments) -nonormalize</GitVersion_ToolArgments>
<GitVersion_ToolArgments Condition=" '$(GitVersion_NoCacheEnabled)' == 'true' ">$(GitVersion_ToolArgments) -nocache</GitVersion_ToolArgments>

<GitVersionTargetFramework Condition="'$(GitVersionTargetFramework)' == ''">$(TargetFramework)</GitVersionTargetFramework>

<GitVersionFileExe Condition="'$(GitVersionFileExe)' == ''">dotnet --roll-forward Major &quot;$([MSBuild]::EnsureTrailingSlash($(MSBuildThisFileDirectory)$(GitVersionTargetFramework)))gitversion.dll&quot;</GitVersionFileExe>
<GitVersionAssemblyFile Condition="'$(GitVersionAssemblyFile)' == ''">$([MSBuild]::EnsureTrailingSlash($(MSBuildThisFileDirectory)$(GitVersionTargetFramework)))GitVersion.MsBuild.dll</GitVersionAssemblyFile>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

<UpdateAssemblyInfo Condition=" '$(UpdateAssemblyInfo)' == 'true' And '$(GenerateGitVersionFiles)' == 'true' ">true</UpdateAssemblyInfo>
<GenerateGitVersionInformation Condition=" '$(GenerateGitVersionInformation)' == '' And '$(GenerateGitVersionFiles)' == 'true' ">true</GenerateGitVersionInformation>

<GitVersionFileExe Condition="'$(GitVersionFileExe)' == ''">dotnet --roll-forward Major &quot;$([MSBuild]::EnsureTrailingSlash($(MSBuildThisFileDirectory)$(TargetFramework)))gitversion.dll&quot;</GitVersionFileExe>
<GitVersionAssemblyFile Condition="'$(GitVersionAssemblyFile)' == ''">$([MSBuild]::EnsureTrailingSlash($(MSBuildThisFileDirectory)$(TargetFramework)))GitVersion.MsBuild.dll</GitVersionAssemblyFile>
</PropertyGroup>

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