Skip to content

Commit

Permalink
Refactor remaining Project and Build files
Browse files Browse the repository at this point in the history
- Simplify project files
  - Add and Update comments
  - Remove unnecessary lines
  - Rearrange and Order code blocks

- Include build root folder
- Rename NuGet Icon to `Icon.png`
- Normalize casing for `ReadMe.md`
- Rename solution file to `CommunityToolkit.sln`
  • Loading branch information
Nirmal4G committed Apr 12, 2022
1 parent 9c87dbf commit 2eb009b
Show file tree
Hide file tree
Showing 22 changed files with 151 additions and 137 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
Expand Down
7 changes: 5 additions & 2 deletions CommunityToolkit.Common/CommunityToolkit.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
<PackageTags>Incremental;Loading;Collection;IncrementalLoadingCollection;String;Array;Extensions;Helpers</PackageTags>
</PropertyGroup>

<!-- .NET Standard 2.1 and .NET 6 already have [NotNullIfNotNull] and [NotNullWhen].
Additionally, also enable trimming support on .NET 6. -->
<!--
NETSTANDARD2_1_OR_GREATER: includes both .NET Standard 2.1 and .NET 6
Those targets already have [NotNullIfNotNull] and [NotNullWhen].
Additionally, also enable trimming support on .NET 6.
-->
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0'">
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
Expand Down
19 changes: 13 additions & 6 deletions CommunityToolkit.Diagnostics/CommunityToolkit.Diagnostics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
</When>

<When Condition="'$(TargetFramework)' == 'netstandard2.1'">

<!-- NETSTANDARD2_1_OR_GREATER: includes both .NET Standard 2.1 and .NET 6 -->
<PropertyGroup>
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
</PropertyGroup>
Expand All @@ -34,7 +36,10 @@
</ItemGroup>
</When>

<!-- Enable trimming support on .NET 6 -->
<!--
NETSTANDARD2_1_OR_GREATER: includes both .NET Standard 2.1 and .NET 6.
Additionally, also enable trimming support on .NET 6.
-->
<When Condition="'$(TargetFramework)' == 'net6.0'">
<PropertyGroup>
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
Expand All @@ -44,6 +49,12 @@
</When>
</Choose>

<!-- T4 service used by the Guard APIs -->
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>

<!-- Text Templates to generate sources -->
<ItemGroup>
<None Update="Generated\Guard.Comparable.Numeric.tt">
<Generator>TextTemplatingFileGenerator</Generator>
Expand All @@ -63,11 +74,7 @@
</None>
</ItemGroup>

<!-- T4 service used by the Guard APIs -->
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>

<!-- Sources generated based on the above text templates -->
<ItemGroup>
<Compile Update="Generated\Guard.Comparable.Numeric.g.cs">
<DesignTime>True</DesignTime>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
- Box&lt;T&gt;: a type mapping boxed value types and exposing some utility and high performance methods.
- Ref&lt;T&gt;: a stack-only struct that can store a reference to a value of a specified type.
- NullableRef&lt;T&gt;: a stack-only struct similar to Ref&lt;T&gt;, which also supports nullable references.
</Description>
</Description>
<PackageTags>Parallel;Performance;Unsafe;Span;Memory;String;StringPool;Array;Stream;Buffer;Extensions;Helpers</PackageTags>
</PropertyGroup>

Expand All @@ -39,33 +39,42 @@

<When Condition="'$(TargetFramework)' == 'netstandard2.1'">

<!-- NETSTANDARD2_1_OR_GREATER: includes both .NET Standard 2.1, .NET Core 3.1 and .NET 6 -->
<PropertyGroup>
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
</PropertyGroup>

<!-- .NET Standard 2.1 doesn't have the Unsafe type -->
<ItemGroup>
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
</ItemGroup>
</When>

<When Condition="'$(TargetFramework)' == 'net6.0'">
<When Condition="'$(TargetFramework)' == 'netcoreapp3.1'">

<!-- NETSTANDARD2_1_OR_GREATER: includes both .NET Standard 2.1, .NET Core 3.1 and .NET 6.
Additionally, also enable trimming support on .NET 6. -->
<!-- NETSTANDARD2_1_OR_GREATER: includes both .NET Standard 2.1, .NET Core 3.1 and .NET 6 -->
<PropertyGroup>
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
</When>

<When Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PropertyGroup>
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
</PropertyGroup>

<!-- .NET Core 3.1 has the Unsafe type, but the version it ships with lacks Unsafe.IsNullRef<T> -->
<ItemGroup>
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
</ItemGroup>
</When>

<When Condition="'$(TargetFramework)' == 'net6.0'">

<!--
NETSTANDARD2_1_OR_GREATER: includes both .NET Standard 2.1, .NET Core 3.1 and .NET 6.
Additionally, also enable trimming support on .NET 6.
-->
<PropertyGroup>
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
</When>
</Choose>

</Project>
Original file line number Diff line number Diff line change
@@ -1,43 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>false</IsPackable>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<!-- Sources that are used by Generator logic in the target projects -->
<ItemGroup>
<Compile Remove="EmbeddedResources\INotifyPropertyChanged.cs" />
<Compile Remove="EmbeddedResources\NotNullAttribute.cs" />
<Compile Remove="EmbeddedResources\NotNullIfNotNullAttribute.cs" />
<Compile Remove="EmbeddedResources\ObservableObject.cs" />
<Compile Remove="EmbeddedResources\ObservableRecipient.cs" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="EmbeddedResources\INotifyPropertyChanged.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="EmbeddedResources\NotNullAttribute.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="EmbeddedResources\NotNullIfNotNullAttribute.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="EmbeddedResources\ObservableObject.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="EmbeddedResources\ObservableRecipient.cs">
<Compile Remove="EmbeddedResources\*.cs" />
<EmbeddedResource Include="EmbeddedResources\*.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

<!--
These files enables tracking Analyzer releases for the rules that ship from this project.
See <https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md>
-->
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" PrivateAssets="all" Pack="false" />
<AdditionalFiles Include="AnalyzerReleases.Shipped.md" />
<AdditionalFiles Include="AnalyzerReleases.Unshipped.md" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="AnalyzerReleases.Shipped.md" />
<AdditionalFiles Include="AnalyzerReleases.Unshipped.md" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" PrivateAssets="All" Pack="false" />
</ItemGroup>

</Project>
</Project>
42 changes: 23 additions & 19 deletions CommunityToolkit.Mvvm/CommunityToolkit.Mvvm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@
<PackageTags>MVVM;Toolkit;MVVMToolkit;INotifyPropertyChanged;Observable;IOC;DI;Dependency Injection;Object Messaging;Extensions;Helpers</PackageTags>
</PropertyGroup>

<!-- Enable trimming support on .NET 6 -->
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0'">
<IsTrimmable>true</IsTrimmable>
<!-- Workaround for .NET 6.0.x regression (see https://github.com/dotnet/linker/issues/2642), enable again when fixed in SDK -->
<EnableTrimAnalyzer>false</EnableTrimAnalyzer>
</PropertyGroup>

<!-- Include the custom .targets file to check the source generator (.NET 6+ is not needed as it guarantees Roslyn 4.x) -->
<ItemGroup Label="Package">
<None Include="CommunityToolkit.Mvvm.targets" Pack="true" PackagePath="buildTransitive\netstandard2.0" />
<None Include="CommunityToolkit.Mvvm.targets" Pack="true" PackagePath="buildTransitive\netstandard2.1" />
<None Include="CommunityToolkit.Mvvm.targets" Pack="true" PackagePath="build\netstandard2.0" />
<None Include="CommunityToolkit.Mvvm.targets" Pack="true" PackagePath="build\netstandard2.1" />
</ItemGroup>

<!-- .NET Standard 2.0 doesn't have the Span<T> and IAsyncEnumerable<T> types -->
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
Expand All @@ -34,32 +49,21 @@
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
</ItemGroup>

<!-- Enable trimming support on .NET 6 -->
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0'">
<IsTrimmable>true</IsTrimmable>

<!-- Workaround for .NET 6.0.x regression (see https://github.com/dotnet/linker/issues/2642), enable again when fixed in SDK -->
<EnableTrimAnalyzer>false</EnableTrimAnalyzer>
</PropertyGroup>

<!-- Source generator project reference for packing -->
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<ProjectReference Include="..\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.csproj"
ReferenceOutputAssembly="false" />
</ItemGroup>

<!--
Pack the source generator to the right package folder.
TODO: Find a way to get the analyzer project's build output path,
and include using NuGet Pack's extensibility target points.
-->
<ItemGroup Label="Package">

<!-- Include the custom .targets file to check the source generator (.NET 6 is not needed as it guarantees Roslyn 4.x) -->
<None Include="CommunityToolkit.Mvvm.targets" PackagePath="buildTransitive\netstandard2.0" Pack="true" />
<None Include="CommunityToolkit.Mvvm.targets" PackagePath="buildTransitive\netstandard2.1" Pack="true" />
<None Include="CommunityToolkit.Mvvm.targets" PackagePath="build\netstandard2.0" Pack="true" />
<None Include="CommunityToolkit.Mvvm.targets" PackagePath="build\netstandard2.1" Pack="true" />

<!-- Pack the source generator to the right package folder -->
<None Include="..\CommunityToolkit.Mvvm.SourceGenerators\bin\$(Configuration)\netstandard2.0\CommunityToolkit.Mvvm.SourceGenerators.dll"
PackagePath="analyzers\dotnet\roslyn4.0\cs"
Pack="true"
Visible="false" />
Pack="true" Visible="false" />
</ItemGroup>

</Project>
30 changes: 16 additions & 14 deletions CommunityToolkit.Mvvm/CommunityToolkit.Mvvm.targets
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets"
DependsOnTargets="_MVVMToolkitGatherAnalyzers">

<!-- Use the CSharpCoreTargetsPath property to find the version of the compiler we are using. This is the same mechanism
MSBuild uses to find the compiler. We could check the assembly version for any compiler assembly (since they all have
the same version) but Microsoft.Build.Tasks.CodeAnalysis.dll is where MSBuild loads the compiler tasks from so if
someone is getting creative with msbuild tasks/targets this is the "most correct" assembly to check. -->
<GetAssemblyIdentity AssemblyFiles="$([System.IO.Path]::Combine(`$([System.IO.Path]::GetDirectoryName($(CSharpCoreTargetsPath)))`,`Microsoft.Build.Tasks.CodeAnalysis.dll`))">
<!--
Use the 'CSharpCoreTargetsPath' property to find the version of the compiler we are using. This is the same mechanism
MSBuild uses to find the compiler. We could check the assembly version for any compiler assembly (since they all have
the same version) but 'Microsoft.Build.Tasks.CodeAnalysis.dll' is where MSBuild loads the compiler tasks from so if
someone is getting creative with msbuild tasks/targets this is the "most correct" assembly to check.
-->
<GetAssemblyIdentity AssemblyFiles="$([System.IO.Path]::Combine('$([System.IO.Path]::GetDirectoryName($(CSharpCoreTargetsPath))'), 'Microsoft.Build.Tasks.CodeAnalysis.dll'))">
<Output TaskParameter="Assemblies" ItemName="CurrentCompilerAssemblyIdentity"/>
</GetAssemblyIdentity>

<PropertyGroup>

<!-- Transform the resulting item from GetAssemblyIdentity into a property representing its assembly version -->
<CurrentCompilerVersion>@(CurrentCompilerAssemblyIdentity->'%(Version)')</CurrentCompilerVersion>

<!-- The CurrentCompilerVersionIsNotNewEnough property can now be defined based on the Roslyn assembly version -->
<!-- The 'CurrentCompilerVersionIsNotNewEnough' property can now be defined based on the Roslyn assembly version -->
<CurrentCompilerVersionIsNotNewEnough Condition="$([MSBuild]::VersionLessThan($(CurrentCompilerVersion), 4.0))">true</CurrentCompilerVersionIsNotNewEnough>
</PropertyGroup>

Expand All @@ -35,12 +35,14 @@
<Analyzer Remove="@(_MVVMToolkitAnalyzer)"/>
</ItemGroup>

<!-- If the source generators are disabled, also emit a warning. This would've been produced by MSBuild itself as well, but
emitting this manually lets us customize the message to inform developers as to why exactly the generators have been
disabled, and that the rest of the MVVM Toolkit will still keep working as intended, just without additional features. -->
<Warning Condition ="'$(CurrentCompilerVersionIsNotNewEnough)' == 'true'" Text="The MVVM Toolkit source generators have been disabled on the current configuration, as they need Roslyn 4.x in order to work. The MVVM Toolkit will work just fine, but features relying on the source generators will not be available."/>
<!--
If the source generators are disabled, also emit a warning. This would've been produced by MSBuild itself as well, but
emitting this manually lets us customize the message to inform developers as to why exactly the generators have been
disabled, and that the rest of the MVVM Toolkit will still keep working as intended, just without additional features.
-->
<Warning Condition ="'$(CurrentCompilerVersionIsNotNewEnough)' == 'true'" Text="The MVVM Toolkit source generators have been disabled on the current configuration, as they need Roslyn 4.x in order to work. The MVVM Toolkit will work just fine, but features relying on the source generators will not be available."/>
</Target>

<!-- Remove the analyzer if Roslyn is missing -->
<Target Name="_MVVMToolkitRemoveAnalyzersForRosynNotFound"
Condition="'$(CSharpCoreTargetsPath)' == ''"
Expand All @@ -53,4 +55,4 @@
</ItemGroup>
</Target>

</Project>
</Project>
2 changes: 1 addition & 1 deletion dotnet Community Toolkit.sln → CommunityToolkit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{88C6FFBE-3
CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md
Contributing.md = Contributing.md
License.md = License.md
README.md = README.md
ReadMe.md = ReadMe.md
ThirdPartyNotices.txt = ThirdPartyNotices.txt
EndProjectSection
EndProject
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<!-- Embed source files that are not tracked by the source control manager to the PDB -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<!-- Include PDB in the built .nupkg -->
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<AllowedOutputExtensionsInPackageBuildOutputFolder>.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions build/Community.Toolkit.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
<Company>.NET Foundation</Company>
<Authors>Microsoft.Toolkit</Authors>
<Product>.NET Community Toolkit</Product>
<CommonTags>dotnet;Community;Toolkit</CommonTags>
<CommonTags>.NET;Community;Toolkit;dotnet</CommonTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Copyright>(c) .NET Foundation and Contributors. All rights reserved.</Copyright>
<PackageProjectUrl>https://github.com/CommunityToolkit/dotnet</PackageProjectUrl>
<PackageReleaseNotes>https://github.com/CommunityToolkit/dotnet/releases</PackageReleaseNotes>
<PackageIcon>Icon.png</PackageIcon>
<PackageIconUrl>https://raw.githubusercontent.com/CommunityToolkit/dotnet/main/build/nuget.png</PackageIconUrl>
</PropertyGroup>

<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Features>Strict</Features>
<Nullable>Enable</Nullable>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<PropertyGroup>
<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
<IsTestProject>$(MSBuildProjectName.EndsWith('Tests'))</IsTestProject>
<IsCoreProject Condition="$(IsTestProject)">False</IsCoreProject>
<IsCoreProject Condition="'$(IsCoreProject)' == ''">True</IsCoreProject>
</PropertyGroup>
Expand All @@ -32,4 +32,4 @@
<ContinuousIntegrationBuild>$(TF_BUILD)</ContinuousIntegrationBuild>
</PropertyGroup>

</Project>
</Project>
6 changes: 3 additions & 3 deletions build/Community.Toolkit.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
</PropertyGroup>

<ItemGroup Condition="$(IsPackable)">
<None Include="$(BuildToolsDirectory)nuget.png" Pack="true" PackagePath="\Icon.png" Visible="False" />
<None Include="$(RepositoryDirectory)License.md" Pack="true" PackagePath="\" Visible="False" />
<None Include="$(RepositoryDirectory)ThirdPartyNotices.txt" Pack="true" PackagePath="\" Visible="False" />
<None Pack="true" PackagePath="\" Visible="False" Include="$(BuildToolsDirectory)Icon.png" />
<None Pack="true" PackagePath="\" Visible="False" Include="$(RepositoryDirectory)License.md" />
<None Pack="true" PackagePath="\" Visible="False" Include="$(RepositoryDirectory)ThirdPartyNotices.txt" />
</ItemGroup>

</Project>
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<ProjectReference Include="..\..\CommunityToolkit.Common\CommunityToolkit.Common.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\CommunityToolkit.Common\CommunityToolkit.Common.csproj" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
</ItemGroup>

</Project>
</Project>
Loading

0 comments on commit 2eb009b

Please sign in to comment.