getsentry / sentry-dotnet

Sentry SDK for .NET
https://docs.sentry.io/platforms/dotnet
MIT License
572 stars 204 forks source link

Allow setting Release via an MSBuild property #3443

Open ericsampson opened 1 week ago

ericsampson commented 1 week ago

Problem Statement

Right now the Release value is constructed via other properties (if not set as an env var), but there are situations where it would be easier to allow the user to explicitly stamp the desired Release as a SentryRelease MSBuild prop.

Solution Brainstorm

No response

bitsandfoxes commented 6 days ago

You can set the SentryRelease from code through the options. Does that not work for you?

ericsampson commented 6 days ago

You can set the SentryRelease from code through the options. Does that not work for you?

No, because that doesn't work nicely in our CI pipeline. I'd like to be able to pass in the SentryRelease as an msbuild property argument to our dotnet publish command.

Does that make sense? Thanks!

bitsandfoxes commented 5 days ago

I see your point. You could set a custom release attribute to be available at runtime. It would look a little something like this

<Target Name="EnsureCustomRelease" BeforeTargets="BeforeBuild">
  <MakeDir Directories="Properties" Condition="!Exists('Properties')" />
  <WriteLinesToFile File="Properties\CustomReleaseInfo.cs" Lines="using System.Reflection%3b" Overwrite="true" />
  <WriteLinesToFile File="Properties\CustomReleaseInfo.cs" Lines="[assembly: AssemblyMetadata(&quot;CustomRelease&quot;, &quot;$(CustomRelease)&quot;)]" Overwrite="false" />
</Target>

That can be retrieved like so

var assembly = Assembly.GetExecutingAssembly();
var customReleaseAttribute = assembly
    .GetCustomAttributes<AssemblyMetadataAttribute>()
    .FirstOrDefault(a => a.Key == "CustomRelease")
    ?.Value;

And you can set it via commandline dotnet publish -p:CustomRelease=1.0.0. Would that unblock you?

jamescrosswell commented 3 days ago

This seems very similar to:

Is there anything we're suggesting in this issue that isn't already covered in the issue above?