Skip to content

Commit f69e533

Browse files
Merge pull request #327 from CommunityToolkit/llama/assemblymetadata
Generate AssemblyInfo from msbuild vs. including in all projects as file
2 parents 9045236 + 577d967 commit f69e533

File tree

48 files changed

+121
-640
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+121
-640
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ bld/
3939

4040
# Visual Studio 2017 auto generated files
4141
Generated\ Files/
42+
*.g.cs
4243

4344
# MSTest test Results
4445
[Tt]est[Rr]esult*/
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
7+
namespace CommunityToolkit.Attributes;
8+
9+
[AttributeUsage(AttributeTargets.Assembly)]
10+
public class PackageProjectUrlAttribute : Attribute
11+
{
12+
public string PackageProjectUrl { get; set; }
13+
14+
public PackageProjectUrlAttribute(string url)
15+
{
16+
PackageProjectUrl = url;
17+
}
18+
}

common/CommunityToolkit.Labs.Shared/CommunityToolkit.Labs.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<Compile Include="$(MSBuildThisFileDirectory)AppLoadingView.xaml.cs">
2222
<DependentUpon>AppLoadingView.xaml</DependentUpon>
2323
</Compile>
24+
<Compile Include="$(MSBuildThisFileDirectory)Attributes\PackageProjectUrlAttribute.cs" />
2425
<Compile Include="$(MSBuildThisFileDirectory)Behaviors\NavigateToUriAction.cs" />
2526
<Compile Include="$(MSBuildThisFileDirectory)Controls\TitleBar\TitleBar.cs" />
2627
<Compile Include="$(MSBuildThisFileDirectory)Converters\SubcategoryToIconConverter.cs" />

common/CommunityToolkit.Labs.Shared/Renderers/Markdown/MarkdownTextBlock.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#endif
1717
#endif
1818

19-
#if __WASM__
19+
#if WASM
2020
using Markdig;
2121
using Uno.Foundation.Interop;
2222
using Uno.UI.Runtime.WebAssembly;
@@ -27,7 +27,7 @@ namespace CommunityToolkit.Labs.Shared.Renderers;
2727
/// <summary>
2828
/// Provide an abstraction around the Toolkit MarkdownTextBlock for both UWP and WinUI 3 in the same namespace (until 8.0) as well as a polyfill for WebAssembly/WASM.
2929
/// </summary>
30-
#if __WASM__
30+
#if WASM
3131
[HtmlElement("div")]
3232
public partial class MarkdownTextBlock : TextBlock
3333
{

common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@
113113
Margin="0,16,0,0"
114114
ColumnSpacing="8">
115115

116-
<StackPanel Orientation="Horizontal"
116+
<StackPanel x:Name="ButtonPanel"
117+
x:Load="{x:Bind renderer:ToolkitDocumentationRenderer.IsProjectPathValid()}"
118+
Orientation="Horizontal"
117119
Spacing="8">
118-
<Button Grid.Column="0"
119-
Visibility="{x:Bind renderer:ToolkitDocumentationRenderer.IsIdValid(Metadata.DiscussionId), Mode=OneWay}">
120+
<Button Visibility="{x:Bind renderer:ToolkitDocumentationRenderer.IsIdValid(Metadata.DiscussionId), Mode=OneWay}">
120121
<StackPanel Orientation="Horizontal">
121122
<FontIcon FontSize="14"
122123
Glyph="&#xE8F2;" />
@@ -125,12 +126,11 @@
125126
</StackPanel>
126127
<interactivity:Interaction.Behaviors>
127128
<interactions:EventTriggerBehavior EventName="Click">
128-
<behaviors:NavigateToUriAction NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToLabsUri('discussions', Metadata.DiscussionId), Mode=OneWay}" />
129+
<behaviors:NavigateToUriAction NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToGitHubUri('discussions', Metadata.DiscussionId), Mode=OneWay}" />
129130
</interactions:EventTriggerBehavior>
130131
</interactivity:Interaction.Behaviors>
131132
</Button>
132-
<Button Grid.Column="1"
133-
Visibility="{x:Bind renderer:ToolkitDocumentationRenderer.IsIdValid(Metadata.IssueId), Mode=OneWay}">
133+
<Button Visibility="{x:Bind renderer:ToolkitDocumentationRenderer.IsIdValid(Metadata.IssueId), Mode=OneWay}">
134134
<StackPanel Orientation="Horizontal">
135135
<PathIcon Margin="-3"
136136
VerticalAlignment="Center"
@@ -147,7 +147,7 @@
147147
</StackPanel>
148148
<interactivity:Interaction.Behaviors>
149149
<interactions:EventTriggerBehavior EventName="Click">
150-
<behaviors:NavigateToUriAction NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToLabsUri('issues', Metadata.IssueId), Mode=OneWay}" />
150+
<behaviors:NavigateToUriAction NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToGitHubUri('issues', Metadata.IssueId), Mode=OneWay}" />
151151
</interactions:EventTriggerBehavior>
152152
</interactivity:Interaction.Behaviors>
153153
</Button>

common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#endif
1616
#endif
1717

18+
#nullable enable
19+
1820
namespace CommunityToolkit.Labs.Shared.Renderers;
1921

2022
/// <summary>
@@ -24,9 +26,16 @@ public sealed partial class ToolkitDocumentationRenderer : Page
2426
{
2527
private const string MarkdownRegexSampleTagExpression = @"^>\s*\[!SAMPLE\s*(?<sampleid>.*)\s*\]\s*$";
2628
private static readonly Regex MarkdownRegexSampleTag = new Regex(MarkdownRegexSampleTagExpression, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Multiline);
29+
private static string? ProjectUrl = null;
2730

2831
public ToolkitDocumentationRenderer()
2932
{
33+
// Check and Cache here before we use in XAML.
34+
if (ProjectUrl == null)
35+
{
36+
ProjectUrl = Assembly.GetExecutingAssembly()?.GetCustomAttribute<CommunityToolkit.Attributes.PackageProjectUrlAttribute>()?.PackageProjectUrl;
37+
}
38+
3039
this.InitializeComponent();
3140
}
3241

@@ -214,11 +223,13 @@ private async void MarkdownTextBlock_LinkClicked(object sender, LinkClickedEvent
214223
}
215224
#endif
216225

217-
public static Uri ToLabsUri(string path, int id) => new Uri($"https://github.com/CommunityToolkit/Labs-Windows/{path}/{id}");
226+
public static Uri? ToGitHubUri(string path, int id) => IsProjectPathValid() ? new Uri($"{ProjectUrl}/{path}/{id}") : null;
218227

219228
public static Visibility IsIdValid(int id) => id switch
220229
{
221230
<= 0 => Visibility.Collapsed,
222231
_ => Visibility.Visible,
223232
};
233+
234+
public static bool IsProjectPathValid() => !string.IsNullOrWhiteSpace(ProjectUrl);
224235
}

common/Labs.Head.Wasm.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
<PackageReference Include="Markdig" Version="0.30.4" />
4040
<PackageReference Include="Microsoft.Windows.Compatibility" Version="5.0.0" />
4141
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
42-
<PackageReference Include="Uno.Extensions.Logging.WebAssembly.Console" Version="1.0.1" />
43-
<PackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" Version="4.0.9" />
42+
<PackageReference Include="Uno.Extensions.Logging.WebAssembly.Console" Version="1.4.0" />
43+
<PackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" Version="4.6.19" />
4444
<PackageReference Include="Uno.Wasm.Bootstrap" Version="3.3.1" />
4545
<PackageReference Include="Uno.Wasm.Bootstrap.DevServer" Version="3.3.1" />
4646
</ItemGroup>

common/Labs.Head.props

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,81 @@
5959

6060
<PropertyGroup>
6161
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
62+
63+
<!-- Turn-off .NET based AssemblyInfo.cs generator, see below -->
64+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
6265
</PropertyGroup>
66+
67+
<!-- https://stackoverflow.com/questions/10980249/msbuild-task-for-setting-custom-attribute-in-assemblyinfo-cs -->
68+
<!-- https://gist.github.com/KirillOsenkov/f20cb84d37a89b01db63f8aafe03f19b -->
69+
<Target Name="AddAssemblyAttributes" BeforeTargets="BeforeCompile">
70+
<PropertyGroup>
71+
<GeneratedAssemblyInfoPath>$(IntermediateOutputPath)AssemblyInfo.g.cs</GeneratedAssemblyInfoPath>
72+
</PropertyGroup>
73+
74+
<ItemGroup>
75+
<!-- Add our own AssemblyInfo.cs standard attributes -->
76+
<AssemblyAttributes Include="AssemblyTitle">
77+
<_Parameter1>$(Product)</_Parameter1>
78+
</AssemblyAttributes>
79+
<AssemblyAttributes Include="AssemblyDescription">
80+
<_Parameter1>Community Toolkit</_Parameter1>
81+
</AssemblyAttributes>
82+
<AssemblyAttributes Include="AssemblyCompany">
83+
<_Parameter1>$(Company)</_Parameter1>
84+
</AssemblyAttributes>
85+
<AssemblyAttributes Include="AssemblyProduct">
86+
<_Parameter1>$(Product)</_Parameter1>
87+
</AssemblyAttributes>
88+
<AssemblyAttributes Include="AssemblyCopyright">
89+
<_Parameter1>$(Copyright)</_Parameter1>
90+
</AssemblyAttributes>
91+
<AssemblyAttributes Include="AssemblyTrademark">
92+
<_Parameter1></_Parameter1>
93+
</AssemblyAttributes>
94+
<AssemblyAttributes Include="AssemblyCulture">
95+
<_Parameter1></_Parameter1>
96+
</AssemblyAttributes>
97+
<AssemblyAttributes Include="AssemblyConfiguration">
98+
<_Parameter1>$(Configuration)</_Parameter1>
99+
</AssemblyAttributes>
100+
<AssemblyAttributes Include="AssemblyVersion">
101+
<_Parameter1>1.0.0.0</_Parameter1>
102+
</AssemblyAttributes>
103+
<AssemblyAttributes Include="AssemblyFileVersion">
104+
<_Parameter1>1.0.0.0</_Parameter1>
105+
</AssemblyAttributes>
106+
<AssemblyAttributes Include="System.Runtime.InteropServices.ComVisible">
107+
<_Parameter1>false</_Parameter1>
108+
<_Parameter1_TypeName>System.Boolean</_Parameter1_TypeName>
109+
</AssemblyAttributes>
110+
111+
<!-- Add custom attributes, also see https://stackoverflow.com/questions/56835671/how-to-read-a-msbuild-property-in-a-given-project-in-runtime -->
112+
<AssemblyAttributes Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(SourceRevisionId)' != ''">
113+
<_Parameter1>CommitHash</_Parameter1>
114+
<_Parameter2>$(SourceRevisionId)</_Parameter2>
115+
</AssemblyAttributes>
116+
<AssemblyAttributes Include="CommunityToolkit.Attributes.PackageProjectUrlAttribute" Condition="'$(PackageProjectUrl)' != ''">
117+
<_Parameter1>$(PackageProjectUrl)</_Parameter1>
118+
</AssemblyAttributes>
119+
<Warning Text="The PackageProjectUrl property was not set." Condition="'$(PackageProjectUrl)' == ''" />
120+
</ItemGroup>
121+
122+
<!-- Extra attributes specific to platforms -->
123+
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true'">
124+
<AssemblyAttributes Include="System.Runtime.Versioning.TargetPlatformAttribute">
125+
<_Parameter1>Windows10.0.19041.0</_Parameter1><!-- TODO: Grab from variable -->
126+
</AssemblyAttributes>
127+
<AssemblyAttributes Include="System.Runtime.Versioning.SupportedOSPlatformAttribute">
128+
<_Parameter1>Windows10.0.17763.0</_Parameter1><!-- TODO: Grab from variable -->
129+
</AssemblyAttributes>
130+
</ItemGroup>
131+
132+
<ItemGroup>
133+
<Compile Include="$(GeneratedAssemblyInfoPath)" />
134+
</ItemGroup>
135+
136+
<!-- Write out new auto-generated AssemblyInfo.g.cs file -->
137+
<WriteCodeFragment Language="C#" OutputFile="$(GeneratedAssemblyInfoPath)" AssemblyAttributes="@(AssemblyAttributes)" />
138+
</Target>
63139
</Project>

labs/CanvasLayout/samples/CanvasLayout.Uwp/CanvasLayout.Uwp.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
<AssemblyName>CanvasLayoutExperiment.Samples.Uwp</AssemblyName>
3636
<ProjectGuid>{C3F460EC-A0A6-4B22-A91A-6CF98B30FD8A}</ProjectGuid>
3737
</PropertyGroup>
38-
<ItemGroup>
39-
<Compile Include="Properties\AssemblyInfo.cs" />
40-
</ItemGroup>
4138
<ItemGroup>
4239
<Content Include="Properties\Default.rd.xml" />
4340
</ItemGroup>

labs/CanvasLayout/samples/CanvasLayout.Uwp/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)