Skip to content

Commit

Permalink
Add new MSBuild files in tools/
Browse files Browse the repository at this point in the history
nike4613 committed Mar 28, 2022
1 parent ef70de3 commit f0928dc
Showing 6 changed files with 241 additions and 0 deletions.
File renamed without changes.
37 changes: 37 additions & 0 deletions tools/Common.CS.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

<!-- C#-specific properties -->
<PropertyGroup>
<LangVersion>10</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable> <!-- C# projects should have nullability enabled. -->
<WarningsAsErrors>$(WarningsAsErrors);nullable</WarningsAsErrors> <!-- Nullability warnings should be errors. -->
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>

<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<GenerateDocumentation>true</GenerateDocumentation>

<ImplicitUsings>false</ImplicitUsings>

<EnableNetAnalyzers>true</EnableNetAnalyzers>
<AnalysisLevel>6.0</AnalysisLevel>
<!-- Because we're bringing in the package ourselves, we wnat to turn this off. -->
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>

<MMSharedSourceFiles>true</MMSharedSourceFiles>

<NoWarn>$(NoWarn);CS1591</NoWarn> <!-- XML documentation warning. TODO: We should probably remove this at some point and ensure that MM is fully documented. -->
<NoWarn>$(NoWarn);CA1716</NoWarn> <!-- Members have name shared with primitive type. -->
</PropertyGroup>

<!-- For our C# projects, we want to pull in the code analyzers -->
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup

</Project>
79 changes: 79 additions & 0 deletions tools/Common.CS.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

<!-- C#-specific targets -->
<Choose>
<When Condition="$(DefineConstants.Contains('NETSTANDARD2_0_OR_GREATER'))">
<!-- .NET Standard -->
<PropertyGroup>
<DefineConstants>NETSTANDARD;$(DefineConstants)</DefineConstants>
<DefineConstants>CECIL0_11;$(DefineConstants)</DefineConstants>
<CecilVersion Condition="'$(CecilVersion)' == ''">0.11.*</CecilVersion>
<NETShimVersion>4.*</NETShimVersion>
</PropertyGroup>
<!-- These are also required when targeting .NET Standard 2.0 to resolve a version conflict with Mono.Cecil's deps. -->
<ItemGroup>
<PackageReference Include="System.Reflection.TypeExtensions" Version="$(NETShimVersion)" />
<PackageReference Include="System.Collections.NonGeneric" Version="$(NETShimVersion)" />
<PackageReference Include="System.ComponentModel.TypeConverter" Version="$(NETShimVersion)" />
<PackageReference Include="System.IO.FileSystem.Primitives" Version="$(NETShimVersion)" />
</ItemGroup>
<!-- This could be made optional at compile-time, but it's preferred to check for availability at runtime. -->
<ItemGroup>
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="$(NETShimVersion)" />
<PackageReference Include="System.Reflection.Emit.ILGeneration" Version="$(NETShimVersion)" />
</ItemGroup>
</When>

<When Condition="$(DefineConstants.Contains('NET40_OR_GREATER'))">
<!-- .NET Framework 4.0+ -->
<PropertyGroup>
<DefineConstants>NETFRAMEWORK4;$(DefineConstants)</DefineConstants>
<DefineConstants>CECIL0_11;$(DefineConstants)</DefineConstants>
<CecilVersion Condition="'$(CecilVersion)' == ''">0.11.*</CecilVersion>
</PropertyGroup>
<ItemGroup>
<!-- <Reference Include="mscorlib" /> -->
<Reference Include="System" />
<!-- .NET Framework 4.0+ reference assemblies aren't always available system-wide. -->
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</When>

<When Condition="$(DefineConstants.Contains('NET35_OR_GREATER'))">
<!-- .NET Framework 3.5 -->
<PropertyGroup>
<DefineConstants>NETFRAMEWORK3;$(DefineConstants)</DefineConstants>
<DefineConstants>CECIL0_10;$(DefineConstants)</DefineConstants>
<CecilVersion Condition="'$(CecilVersion)' == ''">0.10.*</CecilVersion>
</PropertyGroup>
<ItemGroup>
<!-- <Reference Include="mscorlib" /> -->
<Reference Include="System" />
<!-- .NET Framework 3.5 reference assemblies aren't always available system-wide. -->
<PackageReference Include="jnm2.ReferenceAssemblies.net35" Version="1.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</When>

<Otherwise>
<PropertyGruop>
<CoreCompileDependsOn>ErrorBecauseNoSupportedTFM;$(CoreCompileDependsOn)</CoreCompileDependsOn>
</PropertyGroup>
<Target Name="ErrorBecauseNoSupportedTFM">
<Error Text="No supported TFM configuration! Update tools/Common.CS.targets" />
</Target>
</Otherwise>
</Choose>

<!-- Shared source files -->
<ItemGroup Condition="'$(MMSharedSourceFiles)' == 'true'">
<Compile Include="$(MMSourcePath)MonoMod.Common\Shared\**\*.cs" />
</ItemGroup>

</Project>
76 changes: 76 additions & 0 deletions tools/Common.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

<!-- These properties are defaults for ALL project types. C#-specific things must go in Common.CS.props -->
<PropertyGroup>
<Configurations>Debug;Release;DebugTrace;ReleaseTrace</Configurations>
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
<DebugType>portable</DebugType>
<Deterministic>true</Deterministic>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>

<!-- All MonoMod projects (by default) target these frameworks -->
<TargetFrameworks>net35;net452;netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="$(NETCoreAppMaximumVersion) &gt;= 5.0">$(TargetFrameworks);net5.0</TargetFrameworks>
<TargetFrameworks Condition="$(NETCoreAppMaximumVersion) &gt;= 6.0">$(TargetFrameworks);net6.0</TargetFrameworks>
<!-- If a project wants to target some subset or other set, then they can just reassign TargetFrameworks in their project file -->

<!-- Conditional compilation constants are used *everywhere*, make sure common ones are set -->
<DefineConstants>$(AssemblyName.ToUpper().Replace('.', '_'));$(DefineConstants)</DefineConstants>
<!-- TODO: do we even need the assembly constant? the vast majority of shared code has been un-shared -->
<DisableImplicitFrameworkDefines>false</DisableImplicitFrameworkDefines>

<!-- Properties for the repository paths -->
<MMToolsPath>$(MSBuildThisFileDirectory)</MMToolsPath>
<MMRootPath>$(MMToolsPath)..\</MMRootPath>
<MMSourcePath>$(MMRootPath)src\</MMSourcePath>
<MMArtifactsPath>$(MMRootPath)artifacts\</MMArtifactsPath>

<!-- These properties make the build outputs land out-of-source for easy fully clean rebuilds -->
<PackageOutputPath>$(MMArtifactsPath)packages\$(Configuration)\</PackageOutputPath>
<BaseIntermediateOutputPath>$(MMArtifactsPath)obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
<BaseOutputPath>$(MMArtifactsPath)bin\$(MSBuildProjectName)\</BaseOutputPath>

<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>

<!-- Assembly signing -->
<AssemblyOriginatorKeyFile>$(MMRootPath)MonoMod.snk</AssemblyOriginatorKeyFile>
<SignAssembly Condition="'$(SignAssembly)' == 'force'">true</SignAssembly>
<SignAssembly Condition="'$(SignAssembly)' != 'skip'">false</SignAssembly> <!-- default -->
<DelaySign>false</DelaySign>
</PropertyGroup>

<!-- Debug -->
<PropertyGroup Condition="$(Configuration.Contains('Debug'))">
<DebugSymbols>true</DebugSymbols>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;$(DefineConstants)</DefineConstants>
</PropertyGroup>

<!-- Release -->
<PropertyGroup Condition="$(Configuration.Contains('Release'))">
<Optimize>true</Optimize>
<!--<DefineConstants>$(DefineConstants)</DefineConstants>-->
</PropertyGroup>

<!-- Trace -->
<PropertyGroup Condition="$(Configuration.Contains('Trace'))">
<DefineConstants>MONOMOD_DBGLOG;TRACE;$(DefineConstants)</DefineConstants>
</PropertyGroup>

<!-- NuGet Information -->
<Import Project="$(MMToolsPath)NuGet.props" />

<!-- Project Language information -->
<PropertyGroup>
<MMProjectLanguage>Unknown</MMProjectLanguage>
<MMProjectLanguage Condition="'$(MSBuildProjectExtension)' == '.csproj'">CS</MMProjectLanguage>
<MMProjectLanguage Condition="'$(MSBuildProjectExtension)' == '.ilproj'">IL</MMProjectLanguage>
<MMLanguageProps>$(MMToolsPath)Common.$(MMProjectLanguage).props</MMLanguageProps>
<MMLanguageTargets>$(MMToolsPath)Common.$(MMProjectLanguage).targets</MMLanguageTargets>
</PropertyGroup>

<Import Project="$(MMLanguageProps)" Condition="Exists('$(MMLanguageProps)')" />

</Project>
10 changes: 10 additions & 0 deletions tools/Common.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

<!-- This contains common stuff that specific packages may wish to disable. -->


<!-- Include the language-specific targets file, if it exists -->
<Import Project="$(MMLanguageTargets)" Condition="Exists('$(MMLanguageTargets)')" />

</Project>
39 changes: 39 additions & 0 deletions tools/NuGet.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

<PropertyGroup>
<PackageId>$(MSBuildProjectName)</PackageId>
<Authors>0x0ade</Authors> <!-- Note: With dotnet pack, <Authors> is also the list of owners. -->
<Version>$([System.DateTime]::Now.ToString(yy.MM.dd)).00</Version> <!-- Devbuild -->
<Version Condition="'$(BUILD_BUILDNUMBER)' != ''">$(BUILD_BUILDNUMBER)</Version> <!-- Azure Pipelines -->
<Copyright>Copyright $([System.DateTime]::Now.ToString(yyyy)) 0x0ade</Copyright>
<PackageTags>MonoMod;assembly;assemblies;module;modules;il;cil;msil;bytecode;reflection;injection;cecil;mono;$(PackageTags)</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Repository>https://github.com/MonoMod/MonoMod</Repository>
<PackageProjectUrl>https://github.com/MonoMod</PackageProjectUrl>
<PackageIconUrl>https://user-images.githubusercontent.com/1200380/47308180-28242880-d631-11e8-89d2-14d86f3db113.png</PackageIconUrl>
</PropertyGroup>

<!-- We have literally no reason not to use SourceLink -->
<PropertyGroup>
<!-- https://github.com/dotnet/sourcelink -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<ItemGroup>
<!-- SourceLink -->
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<!-- NuGetizer for better control over NuGet package generation with dotnet pack -->
<PackageReference Include="NuGetizer" Version="0.7.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>

0 comments on commit f0928dc

Please sign in to comment.