Skip to content

Commit ecfd480

Browse files
fix: match the runtime's release when an assembly has no informational version
On Windows, FileVersionInfo.ProductVersion falls back to the file version when there's no AssemblyInformationalVersionAttribute, whereas the runtime falls back to the assembly version. When ProductVersion equals the file version but not the assembly version, check whether the assembly references the attribute type before using it. Also skip _GetSentryRelease when the Sentry CLI isn't usable, since nothing would create the release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 2c4ada1 commit ecfd480

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

‎integration-test/cli.Tests.ps1‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ Describe 'Console apps (<framework>) - release creation' -ForEach @(
9090
Should -AnyElementMatch '^releases new release-app@1\.2\.3\+abcdef\s*$'
9191
}
9292

93+
It "creates a release named after the assembly version when there's no informational version" {
94+
BuildWithSentryCLIStub '/p:SentryCreateRelease=true', '/p:GenerateAssemblyInformationalVersionAttribute=false', '/p:FileVersion=7.7.7.7' |
95+
Should -AnyElementMatch '^releases new release-app@1\.0\.0\.0\s*$'
96+
}
97+
98+
It "creates a release named after an informational version that matches the file version" {
99+
BuildWithSentryCLIStub '/p:SentryCreateRelease=true', '/p:InformationalVersion=7.7.7.7', '/p:FileVersion=7.7.7.7' |
100+
Should -AnyElementMatch '^releases new release-app@7\.7\.7\.7\s*$'
101+
}
102+
93103
It "creates a release and sets commits when only SentrySetCommits is enabled" {
94104
$calls = BuildWithSentryCLIStub '/p:SentrySetCommits=true'
95105
$calls | Should -AnyElementMatch '^releases new release-app@1\.2\.3\+abcdef\s*$'

‎src/Sentry/buildTransitive/Sentry.targets‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,21 @@
324324
Log.LogMessage($"Reading version information from: {path}");
325325
var assemblyName = AssemblyName.GetAssemblyName(path);
326326
var name = assemblyName.Name;
327+
var assemblyVersion = assemblyName.Version?.ToString();
327328
Log.LogMessage($"Assembly name: {name}");
328329
329330
// Unlike reflection, this doesn't need to load the types of the assembly's other attributes, see #3536
330-
var version = FileVersionInfo.GetVersionInfo(path).ProductVersion;
331+
var versionInfo = FileVersionInfo.GetVersionInfo(path);
332+
string? version = versionInfo.ProductVersion;
333+
// On Windows, ProductVersion falls back to the file version when there's no informational version attribute
334+
if (version == versionInfo.FileVersion && version != assemblyVersion
335+
&& !Encoding.ASCII.GetString(File.ReadAllBytes(path)).Contains("AssemblyInformationalVersionAttribute\0"))
336+
{
337+
version = null;
338+
}
331339
if (string.IsNullOrWhiteSpace(version))
332340
{
333-
version = assemblyName.Version?.ToString();
341+
version = assemblyVersion;
334342
}
335343
Log.LogMessage($"Version: {version}");
336344
@@ -357,15 +365,15 @@
357365
<_SentryRelease Condition="'$(_SentryRelease)' == '' And '$(SENTRY_RELEASE)' != ''">$(SENTRY_RELEASE)</_SentryRelease>
358366
</PropertyGroup>
359367

360-
<Target Name="_GetSentryRelease" AfterTargets="PrepareSentryCLI" Condition="'$(SentryCreateRelease)' == 'true' And '$(UseSentryCLI)' == 'true'">
368+
<Target Name="_GetSentryRelease" AfterTargets="PrepareSentryCLI" Condition="'$(SentryCreateRelease)' == 'true' And '$(UseSentryCLI)' == 'true' And '$(SentryCLI)' != ''">
361369

362370
<Message Importance="High" Text="Getting Sentry Release..." />
363371

364372
<SentryGetApplicationVersion Condition="'$(_SentryRelease)' == ''" AssemblyPath="$(IntermediateOutputPath)$(TargetName)$(TargetExt)">
365373
<Output TaskParameter="Release" PropertyName="_SentryRelease" />
366374
</SentryGetApplicationVersion>
367375

368-
<Exec ConsoleToMSBuild="true" Condition="'$(_SentryRelease)' == '' And '$(SentryCLI)' != ''"
376+
<Exec ConsoleToMSBuild="true" Condition="'$(_SentryRelease)' == ''"
369377
Command="$(SentryCLIBaseCommand) releases propose-version"
370378
IgnoreExitCode="$(SentryAllowFailure)"
371379
ContinueOnError="$(SentryAllowFailure)">

0 commit comments

Comments
 (0)