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

Refactor common files and resources into a shared project #311

Merged
merged 1 commit into from
Jun 9, 2024
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
14 changes: 12 additions & 2 deletions ThisAssembly.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
src\Directory.props = src\Directory.props
src\Directory.targets = src\Directory.targets
src\Directory.targets.user = src\Directory.targets.user
readme.md = readme.md
src\ThisAssembly.Prerequisites.targets = src\ThisAssembly.Prerequisites.targets
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThisAssembly", "src\ThisAssembly\ThisAssembly.csproj", "{D3A47732-4937-4B6E-BCD1-66896D04E20D}"
Expand Down Expand Up @@ -40,6 +38,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThisAssembly.Resources", "s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThisAssembly.Git", "src\ThisAssembly.Git\ThisAssembly.Git.csproj", "{F34F8470-7C60-4BB8-ACB5-569D6D0F6A46}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Shared", "src\Shared\Shared.shproj", "{8E0F2A43-C9AF-4E46-BF70-CF8645371C12}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -92,4 +92,14 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {ADF2DC9F-5F77-4F6E-8804-CFF5892CD064}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Shared\Shared.projitems*{14d0c5ba-8410-4454-87a2-7bf5993e1ea2}*SharedItemsImports = 5
src\Shared\Shared.projitems*{31c53cce-13fc-4890-803a-85cd146b909b}*SharedItemsImports = 5
src\Shared\Shared.projitems*{3e7158b5-bfef-4416-8226-9096c7c98268}*SharedItemsImports = 5
src\Shared\Shared.projitems*{8e0f2a43-c9af-4e46-bf70-cf8645371c12}*SharedItemsImports = 13
src\Shared\Shared.projitems*{a91c7a07-ffd6-4d19-bd78-b0bc8f9267db}*SharedItemsImports = 5
src\Shared\Shared.projitems*{b5007099-8be7-490b-9e9a-18cc50c92c29}*SharedItemsImports = 5
src\Shared\Shared.projitems*{cddf83bc-70be-46c3-bd79-524d868a2812}*SharedItemsImports = 5
src\Shared\Shared.projitems*{f34f8470-7c60-4bb8-acb5-569d6d0f6a46}*SharedItemsImports = 5
EndGlobalSection
EndGlobal
4 changes: 0 additions & 4 deletions src/Directory.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,4 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)*.cs" />
</ItemGroup>

</Project>
6 changes: 0 additions & 6 deletions src/Directory.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@

<PackageFile Include="$(MSBuildThisFileDirectory)_._" PackagePath="lib/netstandard2.0/_._" />
<PackageFile Include="*.props;*.targets" PackagePath="build\$(TargetFramework)\%(Filename)%(Extension)" Visible="true" />

<!-- Add prerequisites to package -->
<None Include="$(MSBuildThisFileDirectory)ThisAssembly.Prerequisites.targets"
CopyToOutputDirectory="PreserveNewest"
PackagePath="build\$(TargetFramework)\%(Filename)%(Extension)"
Condition="'$(IncludePrerequisites)' != 'false'"/>
</ItemGroup>

</Project>
File renamed without changes.
File renamed without changes.
31 changes: 31 additions & 0 deletions src/Shared/Shared.projitems
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>8e0f2a43-c9af-4e46-bf70-cf8645371c12</SharedGUID>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)**/*$(DefaultLanguageSourceExtension)" Source="Shared" />
<EmbeddedResource Include="$(MSBuildThisFileDirectory)**/*.resx" Source="Shared" />
<None Include="$(MSBuildThisFileDirectory)**/*" Exclude="$(MSBuildThisFileDirectory)*.projitems;$(MSBuildThisFileDirectory)*.shproj" Source="Shared" />
<None Remove="$(MSBuildThisFileDirectory)**/*$(DefaultLanguageSourceExtension)" />
<None Remove="$(MSBuildThisFileDirectory)**/*.resx" />
</ItemGroup>
<ItemGroup>
<Compile Update="@(Compile -&gt; WithMetadataValue('Source', 'Shared'))">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
</Compile>
<EmbeddedResource Update="@(EmbeddedResource -&gt; WithMetadataValue('Source', 'Shared'))">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
</EmbeddedResource>
<None Update="@(None -&gt; WithMetadataValue('Source', 'Shared'))">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
</None>
</ItemGroup>
<ItemGroup>
<!-- Add prerequisites to package -->
<None Update="$(MSBuildThisFileDirectory)*.props;$(MSBuildThisFileDirectory)*.targets" Condition="'$(PackSharedTargets)' != 'false'">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PackagePath>build\$(TargetFramework)\%(Filename)%(Extension)</PackagePath>
</None>
</ItemGroup>
</Project>
16 changes: 16 additions & 0 deletions src/Shared/Shared.shproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>8e0f2a43-c9af-4e46-bf70-cf8645371c12</ProjectGuid>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<Import Project="Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
<ItemGroup>
<PackageFile Remove="ThisAssembly.Prerequisites.targets" />
</ItemGroup>
<ItemGroup>
<UpToDateCheck Remove="ThisAssembly.Prerequisites.targets" />
</ItemGroup>
</Project>
33 changes: 33 additions & 0 deletions src/Shared/ThisAssembly.Prerequisites.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project>

<PropertyGroup>
<!-- Incremental source generator interface appeared first on Roslyn 4.0.1, see
https://learn.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.iincrementalgenerator?view=roslyn-dotnet-4.0.1 -->
<ThisAssemblyMinimumRoslynVersion Condition="'$(ThisAssemblyMinimumRoslynVersion)' == ''">4.0</ThisAssemblyMinimumRoslynVersion>
</PropertyGroup>

<Target Name="_ThisAssemblyCheckCompilerVersion" BeforeTargets="CoreCompile">

<!-- Version comparison functions require MSBuild 16.5+ -->
<Error Text="ThisAssembly requires MSBuild 16.5 or greater."
Condition="$([System.Version]::Parse('16.5.0').CompareTo($([System.Version]::Parse($(MSBuildVersion))))) == 1" />

<PropertyGroup>
<!-- CompilerApiVersion comes from Microsoft.Managed.Core.CurrentVersions.targets -->
<RoslynVersion Condition="'$(CompilerApiVersion)' != ''">$(CompilerApiVersion.Substring(6))</RoslynVersion>
<RoslynVersion Condition="'$(RoslynVersion)' == ''">0.0</RoslynVersion>
</PropertyGroup>

<!-- Don't enforce compiler version for F#, since it's not surfacing the CompilerApiversion at all.
See https://github.com/dotnet/sdk/blob/main/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.PackageDependencyResolution.targets#L214 -->
<Warning Code="THIS001"
Text="ThisAssembly requires Compiler API (Roslyn) version $(ThisAssemblyMinimumRoslynVersion) or greater."
Condition="$([MSBuild]::VersionLessThan('$(RoslynVersion)', '$(ThisAssemblyMinimumRoslynVersion)')) and
('$(Language)' == 'C#' Or '$(Language)' == 'VB')" />
</Target>

<PropertyGroup>
<ThisAssemblyPrerequisitesImported>true</ThisAssemblyPrerequisitesImported>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ on the `ThisAssembly.Info` class.
<None Include="SponsorLink.cs" />
</ItemGroup>

<Import Project="..\Shared\Shared.projitems" Label="Shared" />

</Project>
2 changes: 2 additions & 0 deletions src/ThisAssembly.Constants/ThisAssembly.Constants.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ C#:
<PackageReference Include="PolySharp" Version="1.14.1" PrivateAssets="All" />
</ItemGroup>

<Import Project="..\Shared\Shared.projitems" Label="Shared" />

</Project>
2 changes: 2 additions & 0 deletions src/ThisAssembly.Git/ThisAssembly.Git.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
</ItemGroup>

<Import Project="..\Shared\Shared.projitems" Label="Shared" />

</Project>
2 changes: 2 additions & 0 deletions src/ThisAssembly.Metadata/ThisAssembly.Metadata.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ C#:
<PackageReference Include="PolySharp" Version="1.14.1" PrivateAssets="All" />
</ItemGroup>

<Import Project="..\Shared\Shared.projitems" Label="Shared" />

</Project>
2 changes: 2 additions & 0 deletions src/ThisAssembly.Project/ThisAssembly.Project.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ C#:
<PackageReference Include="PolySharp" Version="1.14.1" PrivateAssets="All" />
</ItemGroup>

<Import Project="..\Shared\Shared.projitems" Label="Shared" />

</Project>
2 changes: 1 addition & 1 deletion src/ThisAssembly.Resources/ResourcesGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
{
context.RegisterPostInitializationOutput(
spc => spc.AddSource(
"ThisAssembly.Resources.EmbeddedResource.cs",
"ThisAssembly.EmbeddedResource.cs",
SourceText.From(EmbeddedResource.GetContent("EmbeddedResource.cs"), Encoding.UTF8)));

var files = context.AdditionalTextsProvider
Expand Down
8 changes: 5 additions & 3 deletions src/ThisAssembly.Resources/ThisAssembly.Resources.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand Down Expand Up @@ -40,11 +40,13 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="..\EmbeddedResource.cs" />
<None Include="SponsorLink.cs" />
</ItemGroup>

<Import Project="..\Shared\Shared.projitems" Label="Shared" />

<ItemGroup>
<None Include="SponsorLink.cs" />
<EmbeddedResource Include="@(Compile -> WithMetadataValue('Filename', 'EmbeddedResource'))" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions src/ThisAssembly.Strings/ThisAssembly.Strings.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@ such as "Hello {name}".
<ItemGroup>
<None Include="SponsorLink.cs" />
</ItemGroup>

<Import Project="..\Shared\Shared.projitems" Label="Shared" />

</Project>
2 changes: 1 addition & 1 deletion src/ThisAssembly.Tests/ThisAssembly.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<Compile Include="..\ThisAssembly.Strings\Model.cs" Link="Model.cs" />
</ItemGroup>

<Import Project="..\ThisAssembly.Prerequisites.targets" />
<Import Project="..\Shared\ThisAssembly.Prerequisites.targets" />
<Import Project="..\*\ThisAssembly*.targets" />

</Project>
3 changes: 2 additions & 1 deletion src/ThisAssembly/ThisAssembly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>true</IsPackable>
<PackBuildOutput>false</PackBuildOutput>
<IncludePrerequisites>false</IncludePrerequisites>
<!-- Whether to include targets from Shared project -->
<PackSharedTargets>false</PackSharedTargets>
</PropertyGroup>

<PropertyGroup>
Expand Down