Skip to content

Commit

Permalink
Merge pull request #159 from mono/remove-unsupported-tfms
Browse files Browse the repository at this point in the history
Remove unsupported TFMs
  • Loading branch information
mhutch authored Oct 2, 2023
2 parents 0053d8d + e7d99ba commit cb66808
Show file tree
Hide file tree
Showing 36 changed files with 123 additions and 98 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

dotnet_style_require_accessibility_modifiers = omit_if_default:warning

# ArgumentNullException.ThrowIfNull not present in some TFMs
dotnet_diagnostic.CA1510.severity = none

# hack: suppress analyzers on the imported file Options.cs
[Options.cs]
generated_code = true
4 changes: 1 addition & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ jobs:
uses: actions/setup-dotnet@v2
with:
dotnet-version: |
2.1.x
3.1.x
5.0.x
6.0.x
7.0.x
- name: Find MSBuild
if: startsWith(matrix.os, 'windows')
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.255" PrivateAssets="all" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" PrivateAssets="all" />
</ItemGroup>

<!-- reproducible build -->
Expand All @@ -29,7 +29,7 @@
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
</ItemGroup>

<PropertyGroup>
Expand Down
2 changes: 2 additions & 0 deletions Mono.TextTemplating.Build.Tests/MSBuildExecutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace Mono.TextTemplating.Tests
{
// MSBuild relies on changing the current working directory to the project directory so we need to run tests serially
[CollectionDefinition (nameof (MSBuildExecutionTests), DisableParallelization = true)]
public class MSBuildExecutionTests : IClassFixture<MSBuildFixture>
{
[Fact]
Expand Down
10 changes: 5 additions & 5 deletions Mono.TextTemplating.Build.Tests/MSBuildTestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public MSBuildTestContext ([CallerMemberName] string testName = null, bool creat

public ProjectCollection Engine { get; }

static ILogger CreateBinLogger (string testName) => new BinaryLogger { Parameters = $"LogFile=binlogs/{testName}.binlog" };
static BinaryLogger CreateBinLogger (string testName) => new BinaryLogger { Parameters = $"LogFile=binlogs/{testName}.binlog" };

public void Dispose ()
{
Expand All @@ -71,7 +71,7 @@ public MSBuildTestProject LoadTestProject (string projectName = null, [CallerMem
}
}

class MSBuildTestProject
sealed class MSBuildTestProject
{
public MSBuildTestProject (MSBuildTestContext context, Project project)
{
Expand Down Expand Up @@ -125,7 +125,7 @@ public MSBuildTestProject WithProperty (string name, string value)
}
}

class MSBuildTestErrorLogger : ILogger
sealed class MSBuildTestErrorLogger : ILogger
{
public List<BuildEventArgs> ErrorsAndWarnings { get; } = new List<BuildEventArgs> ();

Expand Down Expand Up @@ -188,7 +188,7 @@ public static void AssertPaths (this ICollection<ProjectItemInstance> items, par
var actualPaths = items.Select (item => item.GetMetadataValue ("FullPath")).ToHashSet ();
foreach (var expectedPath in expectedFullPaths) {
if (!actualPaths.Remove (expectedPath)) {
throw new Xunit.Sdk.ContainsException (expectedPath, actualPaths);
throw Xunit.Sdk.ContainsException.ForSetItemNotFound ("\"" + expectedPath + "\"", "\"" + string.Join ("\", \"", actualPaths) + "\"");
}
}
Assert.Empty (actualPaths);
Expand Down Expand Up @@ -232,7 +232,7 @@ public static TestDataPath GetIntermediateDirFile (this ProjectInstance instance
=> GetIntermediateDir (instance).Combine (paths);
}

class MSBuildFixture
sealed class MSBuildFixture
{
public MSBuildFixture () => MSBuildTestHelpers.RegisterMSBuildAssemblies ();
}
Expand Down
2 changes: 2 additions & 0 deletions Mono.TextTemplating.Build.Tests/MSBuildTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public static void RegisterMSBuildAssemblies ()
//attempt to read the msbuild.dll location from the launch script
//FIXME: handle quoting in the script
Console.WriteLine ("Found msbuild script in PATH: {0}", msbuildInPath);
#pragma warning disable CA1861 // Avoid constant arrays as arguments
var tokens = File.ReadAllText (msbuildInPath).Split (new [] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
#pragma warning restore CA1861 // Avoid constant arrays as arguments
var filename = tokens.FirstOrDefault (t => t.EndsWith ("MSBuild.dll", StringComparison.OrdinalIgnoreCase));
if (filename != null && File.Exists (filename)) {
var dir = Path.GetDirectoryName (filename);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">net48;$(TargetFrameworks)</TargetFrameworks>
<IsPackable>false</IsPackable>
<DefaultItemExcludes>$(DefaultItemExcludes);TestCases\**</DefaultItemExcludes>
</PropertyGroup>
Expand All @@ -10,32 +11,27 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Locator" Version="1.5.5" />
<PackageReference Include="Microsoft.Build" Version="17.3.1" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Framework" Version="17.3.1" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.3.1" ExcludeAssets="runtime" />
<PackageReference Include="System.Reflection.MetadataLoadContext" Version ="6.0.0" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.6.10" />
<PackageReference Include="Microsoft.Build" Version="17.3.2" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Framework" Version="17.3.2" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.3.2" ExcludeAssets="runtime" />
<PackageReference Include="System.Reflection.MetadataLoadContext" Version="7.0.0" />
<!--
Microsoft.NET.Test.Sdk brings in a version of NuGet.Frameworks that's older than the one used by MSBuild
and loads first, thereby breaking loading of MSBuild assemblies. Force-upgrade it.
-->
<PackageReference Include="NuGet.Frameworks" Version="6.3.1" />
<PackageReference Include="System.Text.Json" Version="6.0.6" />
<PackageReference Include="NuGet.Frameworks" Version="6.7.0" />
<PackageReference Include="System.Text.Json" Version="7.0.3" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<!-- newer versions drop netcoreapp2.1 -->
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
<!-- seems to be required for tests to run on Mono -->
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="17.3.2" Condition="'$(TargetFramework)'=='net472' And $([MSBuild]::IsOSUnixLike())" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1" />
</ItemGroup>

<ItemGroup>
<None Include="TestCases\**\*.*" />
<!-- disable parallel test execution on github actions, it hangs the runner there -->
<None Include="..\Mono.TextTemplating.Tests\xunit.runner.json" CopyToOutputDirectory="PreserveNewest" Condition="'$(GITHUB_ACTIONS)'=='true'" />
<Compile Include="..\Mono.TextTemplating.Tests\Platform.cs" />
<Compile Include="..\Mono.TextTemplating.Tests\TestDataPath.cs" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Mono.TextTemplating.Build/MSBuildTemplateGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Mono.TextTemplating.Build
{
class MSBuildTemplateGenerator : TemplateGenerator
sealed class MSBuildTemplateGenerator : TemplateGenerator
{
public MSBuildTemplateGenerator ()
{
Expand Down
2 changes: 1 addition & 1 deletion Mono.TextTemplating.Build/MSBuildTemplateSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Mono.TextTemplating.Build
{
class MSBuildTemplateSession : ITextTemplatingSession
sealed class MSBuildTemplateSession : ITextTemplatingSession
{
readonly Dictionary<string, object> session = new Dictionary<string, object> ();
readonly MSBuildTemplateGenerator toolTemplateGenerator;
Expand Down
12 changes: 7 additions & 5 deletions Mono.TextTemplating.Build/Mono.TextTemplating.Build.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;net472</TargetFrameworks>
<TargetFrameworks>net48;net6.0</TargetFrameworks>
<PackageId>T4.BuildTools</PackageId>
<Description>MSBuild build targets for the T4 templating language, a general-purpose way to generate text or code files using C#</Description>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand All @@ -10,6 +10,7 @@
end up loading Mono.TextTemplating.dll for the wrong runtime -->
<BuildOutputTargetFolder>buildTasks</BuildOutputTargetFolder>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<NeutralLanguage>en-US</NeutralLanguage>
</PropertyGroup>

<Target Name="AddTargetsFilesToPack" BeforeTargets="GenerateNuspec">
Expand All @@ -29,11 +30,12 @@
</Target>

<ItemGroup>
<PackageReference Include="MessagePackAnalyzer" Version="2.2.85" PrivateAssets="all" />
<PackageReference Include="MessagePack" Version="2.2.85" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Framework" Version="15.1.548" PrivateAssets="all" IncludeAssets="compile" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.1.548" PrivateAssets="all" IncludeAssets="compile" />
<ProjectReference Include="..\Mono.TextTemplating\Mono.TextTemplating.csproj" PrivateAssets="all" />
<PackageReference Include="MessagePackAnalyzer" Version="2.5.129" PrivateAssets="all" />
<PackageReference Include="MessagePack" Version="2.5.129" PrivateAssets="all" />
<!-- intentionally downlevel these so they can be loaded in older VS versions -->
<PackageReference Include="Microsoft.Build.Framework" Version="17.0.0" PrivateAssets="all" IncludeAssets="compile" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.0.0" PrivateAssets="all" IncludeAssets="compile" />
</ItemGroup>

<ItemGroup>
Expand Down
17 changes: 15 additions & 2 deletions Mono.TextTemplating.Build/TemplateBuildState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

using MessagePack;
Expand All @@ -16,10 +17,10 @@ namespace Mono.TextTemplating.Build
[MessagePackObject]
public class TemplateBuildState
{
public const int CURRENT_FORMAT_VERSION = 0;
public const int CurrentFormatVersion = 0;

[Key (0)]
public int FormatVersion { get; set; } = CURRENT_FORMAT_VERSION;
public int FormatVersion { get; set; } = CurrentFormatVersion;
[Key (1)]
public string DefaultNamespace { get; set; }
[Key (2)]
Expand Down Expand Up @@ -185,6 +186,8 @@ public bool Equals (DirectiveProcessor other)
=> Name == other?.Name && Class == other.Name && Assembly == other?.Assembly;

public override bool Equals (object obj) => Equals (obj as DirectiveProcessor);

public override int GetHashCode () => HashCode.Combine (Name, Class, Assembly);
}

[MessagePackObject]
Expand All @@ -203,6 +206,8 @@ public bool Equals (Parameter other)
=> Processor == other?.Processor && Directive == other.Directive && Name == other?.Name && Value == other?.Value;

public override bool Equals (object obj) => Equals (obj as Parameter);

public override int GetHashCode () => HashCode.Combine (Processor, Directive, Name, Value);
}

// TODO: cache warnings
Expand Down Expand Up @@ -280,5 +285,13 @@ public bool IsStale (Func<string, DateTime?> getFileWriteTime, TaskLoggingHelper
return false;
}
}

#if !NETCOREAPP2_1_OR_GREATER
struct HashCode
{
public static int Combine<T1, T2, T3> (T1 value1, T2 value2, T3 value3) => (value1?.GetHashCode () ?? 0) ^ (value2?.GetHashCode () ?? 0) ^ (value3?.GetHashCode () ?? 0);
public static int Combine<T1, T2, T3, T4> (T1 value1, T2 value2, T3 value3, T4 value4) => Combine (value1, value2, value3) ^ (value4?.GetHashCode () ?? 0);
}
#endif
}
}
2 changes: 1 addition & 1 deletion Mono.TextTemplating.Build/TextTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ TemplateBuildState LoadBuildState (string filePath, MessagePackSerializerOptions

var state = MessagePackSerializer.Deserialize<TemplateBuildState> (stream, options);

if (state.FormatVersion != TemplateBuildState.CURRENT_FORMAT_VERSION) {
if (state.FormatVersion != TemplateBuildState.CurrentFormatVersion) {
Log.LogMessageFromResources (MessageImportance.Low, nameof(Messages.BuildStateFormatChanged));
}

Expand Down
2 changes: 1 addition & 1 deletion Mono.TextTemplating.Build/TextTransformProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static MSBuildTemplateGenerator CreateGenerator (TemplateBuildState buildState)
return generator;
}

class WriteTimeCache
sealed class WriteTimeCache
{
public DateTime? GetWriteTime (string filepath)
{
Expand Down
6 changes: 3 additions & 3 deletions Mono.TextTemplating.Roslyn/Mono.TextTemplating.Roslyn.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;net472</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net472;net6.0</TargetFrameworks>
<PackageId>Mono.TextTemplating.Roslyn</PackageId>
<DefaultNamespace>Mono.TextTemplating</DefaultNamespace>
<Description>In-process Roslyn compiler for the Mono.TextTemplating T4 templating engine</Description>
Expand All @@ -11,8 +11,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" />
<None Include="readme.md" Pack="true" PackagePath="\"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" />
<None Include="readme.md" Pack="true" PackagePath="\" />
<ProjectReference Include="..\Mono.TextTemplating\Mono.TextTemplating.csproj" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Mono.TextTemplating.Roslyn/RoslynCodeCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace Mono.TextTemplating
{
class RoslynCodeCompiler : CodeCompiler
sealed class RoslynCodeCompiler : CodeCompiler
{
readonly RuntimeInfo runtime;

Expand Down
4 changes: 1 addition & 3 deletions Mono.TextTemplating.Roslyn/RoslynCodeCompilerException.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Runtime.Serialization;

namespace Mono.TextTemplating
{
[Serializable]
class RoslynCodeCompilerException : Exception
sealed class RoslynCodeCompilerException : Exception
{
public RoslynCodeCompilerException () { }
public RoslynCodeCompilerException (string message) : base (message) { }
public RoslynCodeCompilerException (string message, Exception inner) : base (message, inner) { }
protected RoslynCodeCompilerException (SerializationInfo info, StreamingContext context) : base (info, context) { }
}
}
2 changes: 1 addition & 1 deletion Mono.TextTemplating.Tests/AppDomainTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static TestTemplateGeneratorWithAppDomain CreateGeneratorWithAppDomain (

static string GetAppDomainNameForCurrentTest ([CallerMemberName] string testName = null) => $"Template Test - {testName ?? "(unknown)"}";

class TestTemplateGeneratorWithAppDomain : TemplateGenerator
sealed class TestTemplateGeneratorWithAppDomain : TemplateGenerator
{
AppDomain appDomain;
public TestTemplateGeneratorWithAppDomain (AppDomain appDomain) => this.appDomain = appDomain;
Expand Down
4 changes: 2 additions & 2 deletions Mono.TextTemplating.Tests/GenerateIndentedClassCodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public void FieldAndPropertyGenerated ()
Assert.Equal (expectedOutput, output);
}

static CodeTypeMember CreateBoolField ()
static CodeMemberField CreateBoolField ()
{
var type = new CodeTypeReference (typeof(bool));
return new CodeMemberField { Name = "myField", Type = type };
}

static CodeTypeMember CreateBoolProperty ()
static CodeMemberProperty CreateBoolProperty ()
{
var type = new CodeTypeReference (typeof(bool));
var prop = new CodeMemberProperty { Name = "MyProperty", Type = type };
Expand Down
2 changes: 1 addition & 1 deletion Mono.TextTemplating.Tests/GenerationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static void GenerateOutput (string input, string expectedOutput, string newline)

#region Helpers

static string GenerateCode (ITextTemplatingEngineHost host, string content, string name, string generatorNewline)
static string GenerateCode (DummyHost host, string content, string name, string generatorNewline)
{
var pt = ParsedTemplate.FromTextInternal (content, host);
if (pt.Errors.HasErrors) {
Expand Down
Loading

0 comments on commit cb66808

Please sign in to comment.