-
-
Notifications
You must be signed in to change notification settings - Fork 206
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
Change FileName to be relative to project root #1739
Changes from 9 commits
7c43c6b
b17cef2
cf02e18
7d1408d
d84a50b
b9281cf
d993e8f
d0d5219
69b42d6
5cf4907
52b445f
34783ec
5939c2d
297f31d
ff10b96
59ab8db
6f62a5a
b09f13c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Sentry | ||
{ | ||
internal static class AttributeReader | ||
{ | ||
public static bool TryGetProjectDirectory(Assembly assembly, out string? projectDirectory) | ||
{ | ||
projectDirectory = assembly.GetCustomAttributes<AssemblyMetadataAttribute>() | ||
.SingleOrDefault(x => x.Key == "Sentry.ProjectDirectory") | ||
mattjohnsonpint marked this conversation as resolved.
Show resolved
Hide resolved
|
||
?.Value; | ||
return projectDirectory != null; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<SentryAttributesFile>Sentry.Attributes$(MSBuildProjectExtension.Replace('proj', ''))</SentryAttributesFile> | ||
</PropertyGroup> | ||
<Target Name="WriteSentryAttributes" | ||
Condition="$(Language) == 'VB' or $(Language) == 'C#' or $(Language) == 'F#'" | ||
BeforeTargets="BeforeCompile;CoreCompile" | ||
Inputs="$(MSBuildAllProjects)" | ||
Outputs="$(IntermediateOutputPath)$(SentryAttributesFile)"> | ||
<PropertyGroup> | ||
<SentryAttributesFilePath>$(IntermediateOutputPath)$(SentryAttributesFile)</SentryAttributesFilePath> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<SentryAttributes Include="System.Reflection.AssemblyMetadata"> | ||
<_Parameter1>Sentry.ProjectDirectory</_Parameter1> | ||
<_Parameter2>$(ProjectDir)</_Parameter2> | ||
</SentryAttributes> | ||
<SentryAttributes Include="System.Reflection.AssemblyMetadata" | ||
Condition="'$(SolutionDir)' != '' And '$(SolutionDir)' != '*Undefined*'"> | ||
<_Parameter1>Sentry.SolutionDirectory</_Parameter1> | ||
<_Parameter2>$(SolutionDir)</_Parameter2> | ||
</SentryAttributes> | ||
<!-- Ensure not part of Compile, as a workaround for https://github.com/dotnet/sdk/issues/114 --> | ||
<Compile Remove="$(SentryAttributesFilePath)" /> | ||
</ItemGroup> | ||
<WriteCodeFragment AssemblyAttributes="@(SentryAttributes)" | ||
Language="$(Language)" | ||
OutputFile="$(SentryAttributesFilePath)"> | ||
<Output TaskParameter="OutputFile" ItemName="Compile" Condition="$(Language) != 'F#'" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for some reason the item name for F# is for other languages (like IronRuby) i have not tested. do you want me to include any other languages? Currently they will be a no-op |
||
<Output TaskParameter="OutputFile" ItemName="CompileBefore" Condition="$(Language) == 'F#'" /> | ||
<Output TaskParameter="OutputFile" ItemName="FileWrites" /> | ||
</WriteCodeFragment> | ||
</Target> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using AttributeReader = Sentry.AttributeReader; | ||
|
||
public class AttributeReaderTests | ||
{ | ||
[Fact] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, this should run on iOS AOT'ed so we would see how it behaves there. Assuming the tests are running there following #1703 |
||
public void Simple() | ||
{ | ||
var assembly = typeof(AttributeReaderTests).Assembly; | ||
Assert.True(AttributeReader.TryGetProjectDirectory(assembly, out var projectDirectory)); | ||
Assert.NotNull(projectDirectory); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this safe, and/or does this work with AOT? Like IL2CPP and
net6.0-ios
for example?Just curious if it'll at least return
null
or it'll throw