diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index de684ead96..f2967a295c 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -111,6 +111,23 @@ jobs: id: gitversion uses: gittools/actions/gitversion/execute@v4 + # Export GitVersion outputs as env vars. MSBuild auto-binds env vars whose name + # matches a property to a global property, so every subsequent dotnet build/publish/ + # pack/test in this job — including ones launched by TUnit.Pipeline — stamps the + # correct AssemblyVersion/FileVersion even on AOT recompiles. Without this, a + # publish that triggers a recompile drops AssemblyVersion to 1.0.0.0, and any + # following `pack --no-build` ships a strong-name-mismatched package (issue #5622). + - name: Export version env vars + shell: bash + run: | + { + echo "Version=${{ steps.gitversion.outputs.semVer }}" + echo "AssemblyVersion=${{ steps.gitversion.outputs.assemblySemVer }}" + echo "FileVersion=${{ steps.gitversion.outputs.assemblySemFileVer }}" + echo "InformationalVersion=${{ steps.gitversion.outputs.informationalVersion }}" + echo "PackageVersion=${{ steps.gitversion.outputs.fullSemVer }}" + } >> "$GITHUB_ENV" + - name: Restore shell: bash run: dotnet restore TUnit.CI.slnx diff --git a/TUnit.Pipeline/Modules/PackTUnitFilesModule.cs b/TUnit.Pipeline/Modules/PackTUnitFilesModule.cs index f9f3c44d16..0a51b910af 100644 --- a/TUnit.Pipeline/Modules/PackTUnitFilesModule.cs +++ b/TUnit.Pipeline/Modules/PackTUnitFilesModule.cs @@ -8,8 +8,14 @@ namespace TUnit.Pipeline.Modules; +// Must run after any module that may recompile packable projects (TUnit.Mocks et al). +// This module uses NoBuild=true and packs whatever bin/Release/{tfm}/*.dll is on disk, so +// a racing recompile without version props would ship strong-name-mismatched packages. +// Version props come from $GITHUB_ENV (see .github/workflows/dotnet.yml) so recompiles +// also stamp the correct AssemblyVersion. See issue #5622. [DependsOn] [DependsOn] +[DependsOn] public class PackTUnitFilesModule : Module> { // Packages in beta get a "-beta" suffix appended to their version. diff --git a/TUnit.Pipeline/Modules/PublishNugetTesterAOTModule.cs b/TUnit.Pipeline/Modules/PublishNugetTesterAOTModule.cs index d9a19126b6..03ee0b1067 100644 --- a/TUnit.Pipeline/Modules/PublishNugetTesterAOTModule.cs +++ b/TUnit.Pipeline/Modules/PublishNugetTesterAOTModule.cs @@ -48,7 +48,7 @@ protected override ModuleConfiguration Configure() => ModuleConfiguration.Create Properties = [ new KeyValue("Aot", "true"), - new KeyValue("TUnitVersion", version.ValueOrDefault!.SemVer!) + new KeyValue("TUnitVersion", version.ValueOrDefault!.SemVer!), ], Framework = framework, }, new CommandExecutionOptions