Skip to content
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

Clean-up project files and MSBuild logic #3893

Merged
merged 13 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
25 changes: 15 additions & 10 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<IsPackable>false</IsPackable>
</PropertyGroup>
</Otherwise>
</Choose>

<Choose>
Expand All @@ -45,33 +50,33 @@
<When Condition="'$(Configuration)' == 'Debug' and '$(IsDesignProject)' != 'true'">
<!-- Debug builds have this turned on by default, but it breaks our Xaml Islands Scenarios -->
<PropertyGroup>
<EnableTypeInfoReflection>false</EnableTypeInfoReflection>
<EnableXBindDiagnostics>false</EnableXBindDiagnostics>
<EnableTypeInfoReflection>false</EnableTypeInfoReflection>
</PropertyGroup>
</When>
</Choose>

<Choose>
<When Condition="'$(SourceLinkEnabled)' != 'false' and '$(IsSampleProject)' != 'true'">
<PropertyGroup>
<!-- Optional: Declare that the Repository URL can be published to NuSpec -->
<!-- Declare that the Repository URL can be published to NuSpec -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<!-- Optional: Embed source files that are not tracked by the source control manager to the PDB -->
<!-- Embed source files that are not tracked by the source control manager to the PDB -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<!-- Optional: Include PDB in the built .nupkg -->
<!-- Include PDB in the built .nupkg -->
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.AzureRepos.Git" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.AzureRepos.Git" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
</When>
</Choose>

<Choose>
<When Condition="'$(IsDesignProject)' != 'true'">
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive"/>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
</ItemGroup>
</When>
</Choose>
Expand Down Expand Up @@ -103,10 +108,10 @@
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json">
<Link>stylecop.json</Link>
</AdditionalFiles>
<None Include="$(MSBuildThisFileDirectory)license.md" Pack="true" PackagePath="\"/>
<None Include="$(MSBuildThisFileDirectory)build\nuget.png" Pack="true" PackagePath="images\"/>
<None Include="$(MSBuildThisFileDirectory)License.md" Pack="true" PackagePath="\" />
<None Include="$(MSBuildThisFileDirectory)build\nuget.png" Pack="true" PackagePath="images\" />
</ItemGroup>

<Import Project="$(MSBuildThisFileDirectory)build\Windows.Toolkit.VisualStudio.Design.props" Condition="'$(IsDesignProject)' == 'true'"/>
<Import Project="$(MSBuildThisFileDirectory)build\Windows.Toolkit.VisualStudio.Design.props" Condition="'$(IsDesignProject)' == 'true'" />

</Project>
6 changes: 3 additions & 3 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<Choose>
<!--We'll include signing the Notifications library since we need the DLL signature to match for interop from class libraries to main projects-->
<!-- We'll include signing the Notifications library since we need the DLL signature to match for interop from class libraries to main projects -->
<When Condition="(!$(TargetFramework.Contains(`uap10.0`)) and '$(TargetFramework)' != 'native' and '$(IsSampleProject)' != 'true') or $(MSBuildProjectName) == 'Microsoft.Toolkit.Uwp.Notifications'">
<PropertyGroup>
<SignAssembly>true</SignAssembly>
Expand All @@ -15,11 +15,11 @@
</Choose>

<!--Exclude Notifications project from this since it sets different min versions than what we want for notifications-->
<Import Project="$(MSBuildThisFileDirectory)build\Windows.Toolkit.Uwp.Build.targets" Condition="'$(UseUWP)' == 'true' and $(MSBuildProjectName) != 'Microsoft.Toolkit.Uwp.Notifications'"/>
<Import Project="$(MSBuildThisFileDirectory)build\Windows.Toolkit.Uwp.Build.targets" Condition="'$(UseUWP)' == 'true' and $(MSBuildProjectName) != 'Microsoft.Toolkit.Uwp.Notifications'" />

<Target Name="AddCommitHashToAssemblyAttributes" BeforeTargets="GetAssemblyAttributes">
<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition=" '$(SourceRevisionId)' != '' ">
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(SourceRevisionId)' != ''">
<_Parameter1>CommitHash</_Parameter1>
<_Parameter2>$(SourceRevisionId)</_Parameter2>
</AssemblyAttribute>
Expand Down
12 changes: 2 additions & 10 deletions GazeInputTest/GazeInputTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.12</Version>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.0.2</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.Toolkit.Uwp.Input.GazeInteraction\Microsoft.Toolkit.Uwp.Input.GazeInteraction.csproj">
Expand All @@ -165,11 +162,6 @@
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<!-- No-op to avoid build error when packing solution from commandline -->
<Target Name="Pack" />
</Project>
5 changes: 0 additions & 5 deletions GazeInputTest/Properties/Default.rd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@
Using the Namespace directive to apply reflection policy to all the types in a particular namespace
<Namespace Name="DataClasses.ViewModels" Serialize="All" />
-->

<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<!--
An Assembly element with Name="*Application*" applies to all assemblies in
the application package. The asterisks are not wildcards.
-->
<Assembly Name="*Application*" Dynamic="Required All" />


<!-- Add your application specific runtime directives here. -->


</Application>
</Directives>
File renamed without changes.
21 changes: 11 additions & 10 deletions Microsoft.Toolkit.Diagnostics/Microsoft.Toolkit.Diagnostics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,35 @@
</Description>
<PackageTags>Windows;Community;Toolkit;WCT;UWP;Incremental;Loading;Collection;IncrementalLoadingCollection;String;Array;extensions;helpers</PackageTags>
</PropertyGroup>

<Choose>
<When Condition=" '$(TargetFramework)' == 'netstandard1.4' ">
<When Condition="'$(TargetFramework)' == 'netstandard1.4'">
<!-- .NET Standard 1.4 doesn't have the Span<T> type, ValueTuple or the [Pure] attribute -->
<ItemGroup>

<!-- .NET Standard 1.4 doesn't have the Span<T> type, ValueTuple or the [Pure] attribute -->
Comment on lines -19 to -20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big fan of this change - all XML comments had a blank line before them for consistency (and to more easily distinguish them from normal blocks while just glancing at code), whereas this change breaks that 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do agree on the same but only when the lines look congested. If they are easy on the eyes (in this case) then removing the un-necessary blank lines wouldn't affect readability.

This is also why I put multi-line comment's start and end tag on separate lines to avoid having to add additional new lines.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm either way on the extra blank line, but especially with the ones below, the comments are about the packages, so it seems a bit odd to move them to outside the item group?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is about all 3 packages which are in the ItemGroup, not just System.Diagnostics.Contracts! That's why I moved them.

<PackageReference Include="System.Diagnostics.Contracts" Version="4.3.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="System.Memory" Version="4.5.4" />
</ItemGroup>
</When>
<When Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<ItemGroup>

<!-- .NET Standard 2.0 doesn't have the Span<T> type -->
<When Condition="'$(TargetFramework)' == 'netstandard2.0'">
<!-- .NET Standard 2.0 doesn't have the Span<T> type -->
<ItemGroup>
<PackageReference Include="System.Memory" Version="4.5.4" />
</ItemGroup>
</When>
<When Condition=" '$(TargetFramework)' == 'netstandard2.1' ">

<When Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PropertyGroup>
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
</PropertyGroup>
<!-- .NET Standard 2.1 doesn't have the Unsafe type -->
<ItemGroup>

<!-- .NET Standard 2.1 doesn't have the Unsafe type -->
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
</ItemGroup>
</When>
<When Condition=" '$(TargetFramework)' == 'net5.0' ">

<When Condition="'$(TargetFramework)' == 'net5.0'">
<PropertyGroup>
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@
</Description>
Nirmal4G marked this conversation as resolved.
Show resolved Hide resolved
<PackageTags>Windows;Community;Toolkit;WCT;UWP;core;standard;unsafe;span;memory;string;array;stream;buffer;extensions;helpers;parallel;performance</PackageTags>
</PropertyGroup>

<Choose>
<When Condition=" '$(TargetFramework)' == 'netstandard1.4' ">
<When Condition="'$(TargetFramework)' == 'netstandard1.4'">
<!--
.NET Standard 1.4 lacks the [Pure] attribute, the Rectangle primitive,
the Span<T> and Memory<T> types, the Vector<T> primitive and related APIs,
ValueTask and ValueTask<T>, the Parallel class and the Unsafe class.
We also need to reference the System.Runtime.CompilerServices.Unsafe package directly,
even though System.Memory references it already, as we need a more recent version than
the one bundled with it. This is so that we can use the Unsafe.Unbox<T> method,
which is used by the Box<T> type in the package.
-->
Comment on lines +29 to +38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with the new blank lines around the <Choose> block and before the <When> blocks, and I can see how that can help improve readability. I don't like the arbitrary change of multiline comment style though, as well as the inverted order of defined constants and package references. Also the same remarks about comments I left above apply here as well, with the addition that comments were originally at the same level of the items they were referring to - why the change one level up instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a comment is common to a whole block of code and not just the following line, placing one level above gives clarity.

Same remarks as above for the rest of the changes.

<ItemGroup>

<!-- .NET Standard 1.4 lacks the [Pure] attribute, the Rectangle primitive,
the Span<T> and Memory<T> types, the Vector<T> primitive and related APIs,
ValueTask and ValueTask<T>, the Parallel class and the Unsafe class.
We also need to reference the System.Runtime.CompilerServices.Unsafe package directly,
even though System.Memory references it already, as we need a more recent version than
the one bundled with it. This is so that we can use the Unsafe.Unbox<T> method,
which is used by the Box<T> type in the package. -->
<PackageReference Include="System.Diagnostics.Contracts" Version="4.3.0" />
<PackageReference Include="System.Drawing.Primitives" Version="4.3.0" />
<PackageReference Include="System.Memory" Version="4.5.4" />
Expand All @@ -44,65 +46,70 @@
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
</ItemGroup>
</When>
<When Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<ItemGroup>

<!-- .NET Standard 2.0 doesn't have the Span<T>, HashCode and ValueTask types -->
<When Condition="'$(TargetFramework)' == 'netstandard2.0'">
<!-- .NET Standard 2.0 doesn't have the Span<T>, HashCode and ValueTask types -->
<ItemGroup>
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.0" />
<PackageReference Include="System.Memory" Version="4.5.4" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
</ItemGroup>
</When>
<When Condition=" '$(TargetFramework)' == 'netstandard2.1' ">
<ItemGroup>

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

<!-- NETSTANDARD2_1_OR_GREATER: includes both .NET Standard 2.1 and .NET Core 3.1.
This is needed because .NET Core 3.1 will be a separate package than .NET Standard 2.1. -->
<When Condition="'$(TargetFramework)' == 'netstandard2.1'">
<!--
NETSTANDARD2_1_OR_GREATER: includes both .NET Standard 2.1 and .NET Core 3.1.
This is needed because .NET Core 3.1 will be a separate package than .NET Standard 2.1.
<!-- SPAN_RUNTIME_SUPPORT: define a constant to indicate runtimes with runtime support for
the fast Span<T> type, as well as some overloads with Span<T> parameters (eg. Stream.Write).
In particular, these are runtimes which are able to create Span<T> instances from just
a managed reference, which can be used to slice arbitrary objects not technically supported.
This API (MemoryMarshal.CreateSpan) is not part of .NET Standard 2.0, but it is still
available on .NET Core 2.1. So by using this constant, we can make sure to expose those
APIs relying on that method on all target frameworks that are able to support them. -->
<DefineConstants>NETSTANDARD2_1_OR_GREATER;SPAN_RUNTIME_SUPPORT</DefineConstants>
</PropertyGroup>
</When>
<When Condition=" '$(TargetFramework)' == 'net5.0' ">
SPAN_RUNTIME_SUPPORT: define a constant to indicate runtimes with runtime support for
the fast Span<T> type, as well as some overloads with Span<T> parameters (eg. Stream.Write).
In particular, these are runtimes which are able to create Span<T> instances from just
a managed reference, which can be used to slice arbitrary objects not technically supported.
This API (MemoryMarshal.CreateSpan) is not part of .NET Standard 2.0, but it is still
available on .NET Core 2.1. So by using this constant, we can make sure to expose those
APIs relying on that method on all target frameworks that are able to support them.
-->
<PropertyGroup>
<DefineConstants>NETSTANDARD2_1_OR_GREATER;SPAN_RUNTIME_SUPPORT</DefineConstants>
</PropertyGroup>
</When>
<When Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<!-- .NET Standard 2.1 doesn't have the Unsafe type -->
<ItemGroup>
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
</ItemGroup>
</When>

<When Condition="'$(TargetFramework)' == 'net5.0'">
<PropertyGroup>
<DefineConstants>NETSTANDARD2_1_OR_GREATER;SPAN_RUNTIME_SUPPORT</DefineConstants>
</PropertyGroup>
</When>

<!-- NETCORE_RUNTIME: to avoid issues with APIs that assume a specific memory layout, we define a
.NET Core runtime constant to indicate either .NET Core 2.1 or .NET Core 3.1. These are
runtimes with the same overall memory layout for objects (in particular: strings, SZ arrays,
and ND arrays). We can use this constant to make sure that APIs that are exclusively available
for .NET Standard targets do not make any assumtpion of any internals of the runtime being
actually used by the consumers. .NET 5.0 would fall into this category as well, but we don't
need to include that target as it offers APIs that don't require runtime-based workarounds.-->
<When Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<!--
NETCORE_RUNTIME: to avoid issues with APIs that assume a specific memory layout, we define a
.NET Core runtime constant to indicate either .NET Core 2.1 or .NET Core 3.1. These are
runtimes with the same overall memory layout for objects (in particular: strings, SZ arrays,
and ND arrays). We can use this constant to make sure that APIs that are exclusively available
for .NET Standard targets do not make any assumtpion of any internals of the runtime being
actually used by the consumers. .NET 5.0 would fall into this category as well, but we don't
need to include that target as it offers APIs that don't require runtime-based workarounds.
-->
<PropertyGroup>
<DefineConstants>NETSTANDARD2_1_OR_GREATER;SPAN_RUNTIME_SUPPORT;NETCORE_RUNTIME</DefineConstants>
</PropertyGroup>
</When>
<When Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
<ItemGroup>
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
</ItemGroup>
</When>

<When Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<PropertyGroup>
<DefineConstants>SPAN_RUNTIME_SUPPORT;NETCORE_RUNTIME</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
</ItemGroup>
</When>
</Choose>

Expand Down
4 changes: 2 additions & 2 deletions Microsoft.Toolkit.Mvvm/Microsoft.Toolkit.Mvvm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
</PropertyGroup>

<!-- .NET Standard 2.0 doesn't have the Span<T> and IAsyncEnumerable<T> types -->
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Memory" Version="4.5.4" />
</ItemGroup>

<!-- .NET Standard 2.1 doesn't have the Unsafe type -->
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' ">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
</PropertyGroup>

<ItemGroup>

<ProjectReference Include="..\Microsoft.Toolkit.Uwp\Microsoft.Toolkit.Uwp.csproj" />

</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
<!--
This file contains Runtime Directives, specifications about types your application accesses
through reflection and other dynamic code patterns. Runtime Directives are used to control the
.NET Native optimizer and ensure that it does not remove code accessed by your library. If your
library does not do any reflection, then you generally do not need to edit this file. However,
if your library reflects over types, especially types passed to it or derived from its types,
then you should write Runtime Directives.
The most common use of reflection in libraries is to discover information about types passed
to the library. Runtime Directives have three ways to express requirements on types passed to
your library.
1. Parameter, GenericParameter, TypeParameter, TypeEnumerableParameter
Use these directives to reflect over types passed as a parameter.
2. SubTypes
Use a SubTypes directive to reflect over types derived from another type.
3. AttributeImplies
Use an AttributeImplies directive to indicate that your library needs to reflect over
types or methods decorated with an attribute.
For more information on writing Runtime Directives for libraries, please visit
https://go.microsoft.com/fwlink/?LinkID=391919
-->
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Library Name="Microsoft.Toolkit.Uwp.Connectivity">

<!-- add directives for your library here -->

<!-- add directives for your library here -->
</Library>
</Directives>
Loading