Skip to content

Commit

Permalink
Upgrade to .NET 7 (#1001)
Browse files Browse the repository at this point in the history
  • Loading branch information
nxtn committed Jan 28, 2023
1 parent f5b44b9 commit a6ba416
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 149 deletions.
13 changes: 4 additions & 9 deletions eng/build.yml
Expand Up @@ -25,21 +25,16 @@ strategy:
Release:
BuildConfiguration: Release
steps:
- task: UseDotNet@2
displayName: Install .NET SDK
inputs:
packageType: sdk
version: 6.x
- task: DotNetCoreCLI@2
displayName: Build
inputs:
command: build
projects: src\WinSW.sln
arguments: -c $(BuildConfiguration) -p:Version=$(BuildVersion)
- script: |
dotnet publish src\WinSW\WinSW.csproj -c $(BuildConfiguration) -f net6.0-windows -r win-x64 -p:Version=$(BuildVersion)
dotnet publish src\WinSW\WinSW.csproj -c $(BuildConfiguration) -f net6.0-windows -r win-x86 -p:Version=$(BuildVersion)
dotnet publish src\WinSW\WinSW.csproj -c $(BuildConfiguration) -f net6.0-windows -r win-arm64 -p:Version=$(BuildVersion)
dotnet publish src\WinSW\WinSW.csproj -c $(BuildConfiguration) -f net7.0-windows -r win-x64 --sc -p:Version=$(BuildVersion)
dotnet publish src\WinSW\WinSW.csproj -c $(BuildConfiguration) -f net7.0-windows -r win-x86 --sc -p:Version=$(BuildVersion)
dotnet publish src\WinSW\WinSW.csproj -c $(BuildConfiguration) -f net7.0-windows -r win-arm64 --sc -p:Version=$(BuildVersion)
displayName: Build
- task: DotNetCoreCLI@2
displayName: Test
Expand Down Expand Up @@ -73,7 +68,7 @@ steps:

- publish: artifacts\publish\WinSW-arm64.exe
artifact: WinSW-arm64.exe_$(BuildConfiguration)
displayName: Publish .NET arm64 .exe
displayName: Publish .NET Arm64 .exe

- publish: $(Build.ArtifactStagingDirectory)\WinSW.$(BuildVersion).nupkg
artifact: WinSW.nupkg_$(BuildConfiguration)
Expand Down
4 changes: 3 additions & 1 deletion src/WinSW.Core/AssemblyInfo.cs
@@ -1,4 +1,6 @@
using System.Runtime.CompilerServices;
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyMetadata("IsTrimmable", "True")]
[assembly: InternalsVisibleTo("WinSW")]
[assembly: InternalsVisibleTo("WinSW.Tests")]
10 changes: 5 additions & 5 deletions src/WinSW.Core/WinSW.Core.csproj
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;net6.0-windows</TargetFrameworks>
<LangVersion>preview</LangVersion>
<TargetFrameworks>net461;net7.0-windows</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand All @@ -15,13 +15,13 @@
</PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0-windows'">
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0-windows'">
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="System.Security.AccessControl" Version="6.0.0" />
<PackageReference Include="System.ServiceProcess.ServiceController" Version="5.0.0" />
<PackageReference Include="System.ServiceProcess.ServiceController" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net6.0-windows'">
<ItemGroup Condition="'$(TargetFramework)' != 'net7.0-windows'">
<PackageReference Include="System.Memory" Version="4.5.5" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<Reference Include="System.ServiceProcess" />
Expand Down
1 change: 0 additions & 1 deletion src/WinSW.Core/WrapperService.cs
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
Expand Down
2 changes: 1 addition & 1 deletion src/WinSW.Plugins/WinSW.Plugins.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;net6.0-windows</TargetFrameworks>
<TargetFrameworks>net461;net7.0-windows</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
11 changes: 10 additions & 1 deletion src/WinSW.Tasks/Trim.cs
Expand Up @@ -17,13 +17,18 @@ public override bool Execute()
{
using var module = ModuleDefinition.ReadModule(this.Path, new() { ReadWrite = true, ReadSymbols = true });

foreach (var t in module.CustomAttributeTypes())
{
this.WalkType(t);
}

this.WalkType(module.EntryPoint.DeclaringType);

var types = module.Types;
for (int i = types.Count - 1; i >= 0; i--)
{
var type = types[i];
if (type.FullName.Contains("WinSW.Plugins"))
if (type.FullName.StartsWith("WinSW.Plugins"))
{
this.WalkType(type);
}
Expand Down Expand Up @@ -64,6 +69,10 @@ private void WalkType(TypeReference typeRef)
this.WalkType(genericArg);
}
}
else if (typeRef is IModifierType modifierType)
{
this.WalkType(modifierType.ModifierType);
}

return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/WinSW.Tasks/WinSW.Tasks.csproj
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.2.0" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.4.0" />
<PackageReference Include="Mono.Cecil" Version="0.11.4" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/WinSW.Tests/CommandLineTests.cs
Expand Up @@ -77,7 +77,7 @@ public void FailOnUnknownCommand()

var result = Helper.ErrorTest(new[] { commandName });

Assert.Equal($"Unrecognized command or argument '{commandName}'\r\n\r\n", result.Error);
Assert.Equal($"Unrecognized command or argument '{commandName}'.\r\n\r\n", result.Error);
}

/// <summary>
Expand Down
14 changes: 7 additions & 7 deletions src/WinSW.Tests/WinSW.Tests.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net471;net6.0-windows</TargetFrameworks>
<TargetFrameworks>net471;net7.0-windows</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand All @@ -12,15 +12,15 @@
</PackageReference>
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="2.0.226801" />
<PackageReference Include="Microsoft.Diagnostics.Runtime.Utilities" Version="2.0.0-rc.20303.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net6.0-windows'">
<ItemGroup Condition="'$(TargetFramework)' != 'net7.0-windows'">
<PackageReference Include="System.Reflection.Metadata" Version="5.0.0" />
<Reference Include="System.ServiceProcess" />
</ItemGroup>
Expand All @@ -39,11 +39,11 @@

<Target Name="Copy" BeforeTargets="AfterBuild">

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0-windows'">
<_FilesToCopy Include="$(ArtifactsBinDir)WinSW\$(Configuration)\net6.0-windows\WinSW.runtimeconfig*.json" />
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0-windows'">
<_FilesToCopy Include="$(ArtifactsBinDir)WinSW\$(Configuration)\net7.0-windows\WinSW.runtimeconfig*.json" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net6.0-windows'">
<ItemGroup Condition="'$(TargetFramework)' != 'net7.0-windows'">
<_FilesToCopy Include="$(ArtifactsBinDir)WinSW\$(Configuration)\net461\System.ValueTuple.dll" />
</ItemGroup>

Expand Down
4 changes: 3 additions & 1 deletion src/WinSW/AssemblyInfo.cs
@@ -1,3 +1,5 @@
using System.Runtime.CompilerServices;
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyMetadata("IsTrimmable", "True")]
[assembly: InternalsVisibleTo("WinSW.Tests")]
41 changes: 41 additions & 0 deletions src/WinSW/CommandExtensions.cs
@@ -0,0 +1,41 @@
using System;
using System.CommandLine;
using System.CommandLine.Invocation;

namespace WinSW
{
internal static class CommandExtensions
{
internal static void SetHandler<T>(this Command command, Action<T, InvocationContext> handle, Argument<T> symbol)
{
command.SetHandler(context =>
{
var value = context.ParseResult.GetValueForArgument(symbol);
handle(value!, context);
});
}

internal static void SetHandler<T1, T2, T3>(this Command command, Action<T1, T2, T3, InvocationContext> handle, Argument<T1> symbol1, Option<T2> symbol2, Option<T3> symbol3)
{
command.SetHandler(context =>
{
var value1 = context.ParseResult.GetValueForArgument(symbol1);
var value2 = context.ParseResult.GetValueForOption(symbol2);
var value3 = context.ParseResult.GetValueForOption(symbol3);
handle(value1!, value2!, value3!, context);
});
}

internal static void SetHandler<T1, T2, T3, T4>(this Command command, Action<T1, T2, T3, T4, InvocationContext> handle, Argument<T1> symbol1, Option<T2> symbol2, Option<T3> symbol3, Option<T4> symbol4)
{
command.SetHandler(context =>
{
var value1 = context.ParseResult.GetValueForArgument(symbol1);
var value2 = context.ParseResult.GetValueForOption(symbol2);
var value3 = context.ParseResult.GetValueForOption(symbol3);
var value4 = context.ParseResult.GetValueForOption(symbol4);
handle(value1!, value2!, value3!, value4!, context);
});
}
}
}

0 comments on commit a6ba416

Please sign in to comment.