Skip to content

Commit 8473017

Browse files
committed
Simplify MSBuild logic in project files
- Add necessary guard to check for pack. - Remove redundant properties and values. - Remove and adjust quotes in property functions. - Use wildcards to generalize and reduce items declared.
1 parent c5547bc commit 8473017

12 files changed

+48
-92
lines changed

CommunityToolkit.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Root", "Root", "{CFA75BE0-5
1717
EndProject
1818
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{CD16E790-7B7B-411E-9CE7-768E759CC22D}"
1919
ProjectSection(SolutionItems) = preProject
20+
eng\AssemblyInfo.Shared.cs = eng\AssemblyInfo.Shared.cs
2021
eng\Sign-Package.ps1 = eng\Sign-Package.ps1
2122
eng\SignClientSettings.json = eng\SignClientSettings.json
2223
eng\Toolkit.Common.props = eng\Toolkit.Common.props

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<!-- Embed source files that are not tracked by the source control manager to the PDB -->
2020
<EmbedUntrackedSources>true</EmbedUntrackedSources>
2121
<!-- Include PDB in the built .nupkg -->
22-
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
22+
<AllowedOutputExtensionsInPackageBuildOutputFolder>.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
2323
</PropertyGroup>
2424
<ItemGroup>
2525
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />

eng/AssemblyInfo.Shared.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
// This file contains assembly and module attributes that is shared across projects.
6+
// Include it in `Directory.Build.targets` near to all projects that need this file.
7+
8+
using System.Runtime.CompilerServices;
9+
10+
/*
11+
Using `[module: SkipLocalsInit]` suppresses the .init flag for local variables for the entire module.
12+
This doesn't affect the correctness of the methods in this assembly, as none of them are relying on
13+
JIT ensuring that all local memory is zeroed out to work. Doing this can provide some minor
14+
performance benefits, depending on the workload.
15+
*/
16+
[module: SkipLocalsInit]

eng/Toolkit.Common.targets

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22

3-
<PropertyGroup>
3+
<PropertyGroup Condition="'$(IsPackable)' == 'true'">
44
<Company>Microsoft</Company>
55
<Authors>Microsoft</Authors>
66
<Product>.NET Community Toolkit</Product>
@@ -13,19 +13,25 @@
1313
<PackageIcon>Icon.png</PackageIcon>
1414
</PropertyGroup>
1515

16-
<PropertyGroup>
16+
<PropertyGroup Condition="'$(IsPackable)' == 'true'">
1717
<!-- TODO: Dynamically generate Title if one wasn't set -->
1818
<Title Condition="'$(Title)' == ''">$(Product) Asset</Title>
1919
<PackageTags Condition="'$(PackageTags)' != ''">$(CommonTags);$(PackageTags)</PackageTags>
2020
<PackageTags Condition="'$(PackageTags)' == ''">$(CommonTags)</PackageTags>
2121
</PropertyGroup>
2222

23-
<ItemGroup Condition="$(IsPackable)">
23+
<ItemGroup Condition="'$(IsPackable)' == 'true'">
2424
<None Pack="true" PackagePath="\" Visible="False" Include="$(BuildToolsDirectory)Icon.png" />
2525
<None Pack="true" PackagePath="\" Visible="False" Include="$(RepositoryDirectory)License.md" />
2626
<None Pack="true" PackagePath="\" Visible="False" Include="$(RepositoryDirectory)ThirdPartyNotices.txt" />
2727
</ItemGroup>
2828

29+
<!-- Checked Version properties to use down the line -->
30+
<PropertyGroup Condition="'$([MSBuild]::GetTargetFrameworkIdentifier($(TargetFramework)))' == '.NETCoreApp'">
31+
<_ToolkitTargetFrameworkVersion>$([MSBuild]::GetTargetFrameworkVersion($(TargetFramework)))</_ToolkitTargetFrameworkVersion>
32+
<_NET_6_OR_GREATER>$([MSBuild]::VersionGreaterThanOrEquals($(_ToolkitTargetFrameworkVersion), '6.0'))</_NET_6_OR_GREATER>
33+
</PropertyGroup>
34+
2935
<!--
3036
Add additional Pre-Processor symbols to $(DefineConstants) and $(FinalDefineConstants) in VB.
3137
This overrides the same target in the .NET SDK. Since, that version has issues in DesignTime.

eng/Toolkit.TextTemplates.targets

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,17 @@
66
</ItemGroup>
77

88
<ItemGroup>
9-
<None Update="Generated\Guard.Comparable.Numeric.tt">
9+
<None Update="**\*.tt">
1010
<Generator>TextTemplatingFileGenerator</Generator>
11-
<LastGenOutput>Guard.Comparable.Numeric.g.cs</LastGenOutput>
12-
</None>
13-
<None Update="Generated\Guard.Collection.tt">
14-
<Generator>TextTemplatingFileGenerator</Generator>
15-
<LastGenOutput>Guard.Collection.g.cs</LastGenOutput>
16-
</None>
17-
<None Update="Generated\ThrowHelper.Collection.tt">
18-
<Generator>TextTemplatingFileGenerator</Generator>
19-
<LastGenOutput>ThrowHelper.Collection.g.cs</LastGenOutput>
20-
</None>
21-
<None Update="Generated\TypeInfo.ttinclude">
22-
<Generator>TextTemplatingFileGenerator</Generator>
23-
<LastGenOutput>TypeInfo.g.cs</LastGenOutput>
11+
<LastGenOutput>%(Filename).g.cs</LastGenOutput>
2412
</None>
2513
</ItemGroup>
2614

2715
<ItemGroup>
28-
<Compile Update="Generated\Guard.Comparable.Numeric.g.cs">
29-
<DesignTime>True</DesignTime>
16+
<Compile Update="**\*.g.cs">
3017
<AutoGen>True</AutoGen>
31-
<DependentUpon>Guard.Comparable.Numeric.tt</DependentUpon>
32-
</Compile>
33-
<Compile Update="Generated\Guard.Collection.g.cs">
3418
<DesignTime>True</DesignTime>
35-
<AutoGen>True</AutoGen>
36-
<DependentUpon>Guard.Collection.tt</DependentUpon>
37-
</Compile>
38-
<Compile Update="Generated\ThrowHelper.Collection.g.cs">
39-
<DesignTime>True</DesignTime>
40-
<AutoGen>True</AutoGen>
41-
<DependentUpon>ThrowHelper.Collection.tt</DependentUpon>
42-
</Compile>
43-
<Compile Update="Generated\TypeInfo.g.cs">
44-
<DesignTime>True</DesignTime>
45-
<AutoGen>True</AutoGen>
46-
<DependentUpon>TypeInfo.ttinclude</DependentUpon>
19+
<DependentUpon>$([System.IO.Path]::ChangeExtension(%(Filename), '.tt'))</DependentUpon>
4720
</Compile>
4821
</ItemGroup>
4922

src/CommunityToolkit.HighPerformance/CommunityToolkit.HighPerformance.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
<!-- On .NET Standard 2.0, the unit test project also needs access to internals -->
4141
<ItemGroup>
42-
<InternalsVisibleTo Include="CommunityToolkit.HighPerformance.UnitTests, PublicKey=$(AssemblySignPublicKey)" />
42+
<InternalsVisibleTo Include="CommunityToolkit.HighPerformance.UnitTests" />
4343
</ItemGroup>
4444

4545
<!-- .NET Standard 2.0 doesn't have the Span<T>, HashCode and ValueTask types -->

src/CommunityToolkit.Mvvm/CommunityToolkit.Mvvm.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
<!-- Add the [InternalsVisibleTo] attribute for the test project -->
4141
<ItemGroup>
42-
<InternalsVisibleTo Include="CommunityToolkit.Mvvm.Internals.UnitTests, PublicKey=$(AssemblySignPublicKey)" />
42+
<InternalsVisibleTo Include="CommunityToolkit.Mvvm.Internals.UnitTests" />
4343
</ItemGroup>
4444

4545
<!--

src/CommunityToolkit.Mvvm/CommunityToolkit.Mvvm.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
the same version) but Microsoft.Build.Tasks.CodeAnalysis.dll is where MSBuild loads the compiler tasks from so if
2020
someone is getting creative with msbuild tasks/targets this is the "most correct" assembly to check.
2121
-->
22-
<GetAssemblyIdentity AssemblyFiles="$([System.IO.Path]::Combine(`$([System.IO.Path]::GetDirectoryName($(CSharpCoreTargetsPath)))`,`Microsoft.Build.Tasks.CodeAnalysis.dll`))">
22+
<GetAssemblyIdentity AssemblyFiles="$([System.IO.Path]::Combine($([System.IO.Path]::GetDirectoryName($(CSharpCoreTargetsPath))), 'Microsoft.Build.Tasks.CodeAnalysis.dll'))">
2323
<Output TaskParameter="Assemblies" ItemName="MVVMToolkitCurrentCompilerAssemblyIdentity"/>
2424
</GetAssemblyIdentity>
2525

src/Directory.Build.props

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22

3-
<Import Project="..\Directory.Build.props" />
3+
<Import Project="..\$(MSBuildThisFile)" />
44

55
<PropertyGroup>
66
<IsPackable>true</IsPackable>
@@ -12,10 +12,7 @@
1212

1313
<!-- Include PolySharp to generate polyfills for all projects (on their .NET Standard 2.x targets) -->
1414
<ItemGroup>
15-
<PackageReference Include="PolySharp" Version="1.8.1">
16-
<PrivateAssets>all</PrivateAssets>
17-
<IncludeAssets>build; analyzers</IncludeAssets>
18-
</PackageReference>
15+
<PackageReference Include="PolySharp" Version="1.8.1" PrivateAssets="All" IncludeAssets="Analyzers;Build" />
1916
</ItemGroup>
2017

2118
</Project>

src/Directory.Build.targets

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,19 @@
11
<Project>
22

3-
<Import Project="..\Directory.Build.targets" />
3+
<Import Project="..\$(MSBuildThisFile)" />
44

5-
<!-- Define NETSTANDARD2_1_OR_GREATER for .NET Standard 2.1 targets and above -->
6-
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net7.0'">
7-
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
8-
</PropertyGroup>
9-
10-
<!-- Configure trimming for projects on .NET 6 and above -->
11-
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net7.0'">
12-
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
5+
<PropertyGroup Condition="'$(_NET_6_OR_GREATER)' == 'true'">
136
<IsTrimmable>true</IsTrimmable>
7+
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
8+
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
149
</PropertyGroup>
1510

16-
<!--
17-
The following target has been ported from TerraFX.Interop.Windows.
18-
See: https://github.com/terrafx/terrafx.interop.windows.
19-
Using [module: SkipLocalsInit] suppresses the .init flag for local variables for the entire module.
20-
This doesn't affect the correctness of methods in this assembly, as none of them are relying on the
21-
JIT ensuring that all local memory is zeroed out to work. Doing this can provide some minor
22-
performance benefits, depending on the workload.
23-
-->
24-
<PropertyGroup>
25-
<GeneratedSkipLocalsInitFile Condition="'$(GeneratedSkipLocalsInitFile)' == ''">$(IntermediateOutputPath)$(MSBuildProjectName).SkipLocalsInit.g.cs</GeneratedSkipLocalsInitFile>
26-
<GeneratedSkipLocalsInitFileLines>
27-
<![CDATA[//------------------------------------------------------------------------------
28-
// <auto-generated>
29-
// This code was generated by a tool.
30-
//
31-
// Changes to this file may cause incorrect behavior and will be lost if
32-
// the code is regenerated.
33-
// </auto-generated>
34-
//------------------------------------------------------------------------------
35-
36-
[module: global::System.Runtime.CompilerServices.SkipLocalsInitAttribute]]]>
37-
</GeneratedSkipLocalsInitFileLines>
38-
</PropertyGroup>
39-
40-
<Target Name="GenerateSkipLocalsInit"
41-
BeforeTargets="BeforeCompile;CoreCompile"
42-
DependsOnTargets="PrepareForBuild"
43-
Condition="'$(Language)' == 'C#'"
44-
Inputs="$(MSBuildAllProjects)"
45-
Outputs="$(GeneratedSkipLocalsInitFile)">
46-
47-
<!-- Write the file with the attribute -->
48-
<WriteLinesToFile Lines="$(GeneratedSkipLocalsInitFileLines)" Overwrite="true" WriteOnlyWhenDifferent="true" File="$(GeneratedSkipLocalsInitFile)" />
11+
<ItemGroup>
12+
<Compile Include="$(BuildToolsDirectory)AssemblyInfo.Shared.cs" LinkBase="Properties" Visible="False" />
13+
</ItemGroup>
4914

50-
<!-- Include the generated file in the list of files to compile -->
51-
<ItemGroup>
52-
<Compile Include="$(GeneratedSkipLocalsInitFile)" />
53-
</ItemGroup>
54-
</Target>
15+
<ItemGroup>
16+
<InternalsVisibleTo Update="@(InternalsVisibleTo)" PublicKey="$(AssemblySignPublicKey)" Condition="@(InternalsVisibleTo->Count()) != 0" />
17+
</ItemGroup>
5518

5619
</Project>

tests/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22

3-
<Import Project="..\Directory.Build.props" />
3+
<Import Project="..\$(MSBuildThisFile)" />
44

55
<PropertyGroup>
66
<IsPackable>false</IsPackable>

tests/Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22

3-
<Import Project="..\Directory.Build.targets" />
3+
<Import Project="..\$(MSBuildThisFile)" />
44

55
<!-- MSTest v2 -->
66
<ItemGroup Condition="'$(IsTestProject)' == 'true'">

0 commit comments

Comments
 (0)