Skip to content

Commit

Permalink
Target net7.0 and update packages (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkl authored Dec 7, 2022
1 parent 69f27e5 commit 247cbc0
Show file tree
Hide file tree
Showing 21 changed files with 1,008 additions and 954 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ env:
ContinuousIntegrationBuild: 'true'
DotNet3Version: '3.x'
DotNet6Version: '6.x'
DotNet7Version: '7.x'

jobs:
BuildAndTest:
Expand All @@ -31,6 +32,7 @@ jobs:
name: Linux
- os: macos-latest
name: MacOS
fail-fast: false

name: Build and Test (${{ matrix.name }})
runs-on: ${{ matrix.os }}
Expand All @@ -42,28 +44,38 @@ jobs:
fetch-depth: 0

- name: Install .NET ${{ env.DotNet3Version }}
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DotNet3Version }}

- name: Install .NET ${{ env.DotNet6Version }}
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DotNet6Version }}

- name: Install .NET ${{ env.DotNet7Version }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DotNet7Version }}

- name: Build Solution
run: dotnet build "/Property:Platform=${{ env.BuildPlatform }};Configuration=${{ env.BuildConfiguration }}" "/BinaryLogger:${{ env.ArtifactsDirectoryName }}/build.binlog"

- name: Run Unit Tests (.NET Framework)
if: ${{ matrix.os == 'windows-latest' }}
if: ${{ matrix.name == 'Windows' }}
run: dotnet test --logger trx --no-restore --no-build --framework net472 /noautorsp "/Property:Platform=${{ env.BuildPlatform }};Configuration=${{ env.BuildConfiguration }}" "/BinaryLogger:${{ env.ArtifactsDirectoryName }}/test-net472.binlog"

- name: Run Unit Tests (.NET Core 3.1)
if: ${{ matrix.name != 'MacOS' }}
run: dotnet test --logger trx --no-restore --no-build --framework netcoreapp3.1 /noautorsp "/Property:Platform=${{ env.BuildPlatform }};Configuration=${{ env.BuildConfiguration }}" "/BinaryLogger:${{ env.ArtifactsDirectoryName }}/test-netcoreapp3.1.binlog"

- name: Run Unit Tests (.NET 6)
if: ${{ matrix.name != 'MacOS' }}
run: dotnet test --logger trx --no-restore --no-build --framework net6.0 /noautorsp "/Property:Platform=${{ env.BuildPlatform }};Configuration=${{ env.BuildConfiguration }}" "/BinaryLogger:${{ env.ArtifactsDirectoryName }}/test-net6.0.binlog"

- name: Run Unit Tests (.NET 7)
run: dotnet test --logger trx --no-restore --no-build --framework net7.0 /noautorsp "/Property:Platform=${{ env.BuildPlatform }};Configuration=${{ env.BuildConfiguration }}" "/BinaryLogger:${{ env.ArtifactsDirectoryName }}/test-net7.0.binlog"

- name: Upload Test Results
uses: actions/upload-artifact@v2
if: success() || failure()
Expand Down
16 changes: 8 additions & 8 deletions Packages.props
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MicrosoftBuildPackageVersion>17.3.1</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion>17.4.0</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion Condition="'$(TargetFramework)' == 'net6.0'">17.3.2</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion Condition="'$(TargetFramework)' == 'netcoreapp3.1'">16.9.0</MicrosoftBuildPackageVersion>
<NuGetPackageVersion>6.3.0</NuGetPackageVersion>
<NuGetPackageVersion>6.4.0</NuGetPackageVersion>
<NuGetPackageVersion Condition="'$(TargetFramework)' == 'netcoreapp3.1'">5.7.1</NuGetPackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Update="Microsoft.Build" Version="$(MicrosoftBuildPackageVersion)" />
<PackageReference Update="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildPackageVersion)" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="4.3.1" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" />
<PackageReference Update="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.3" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Update="Microsoft.VisualStudio.SDK.EmbedInteropTypes" Version="15.0.36" />
<PackageReference Update="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="3.3.2180" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Update="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="3.4.2244" />
<PackageReference Update="NuGet.Frameworks" Version="$(NuGetPackageVersion)" />
<PackageReference Update="Shouldly" Version="4.1.0" />
<PackageReference Update="System.IO.Compression" Version="4.3.0" />
<PackageReference Update="xunit" Version="2.4.2" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.5" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="Microsoft.Build.Artifacts" Version="4.0.4" />
<GlobalPackageReference Include="Microsoft.Build.Artifacts" Version="4.2.0" />
<GlobalPackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.5.113" />
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.5.119" />
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" />
<Compile Include="..\Shared\GlobalSuppressions.cs" />
<AdditionalFiles Include="..\Shared\stylecop.json" />
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.0",
"version": "7.0.0",
"rollForward": "latestMinor"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks Condition="'$(MSBuildAssemblyVersion)' &gt;= '17.0'">net472;netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks Condition="'$(MSBuildAssemblyVersion)' &gt;= '17.0'">net472;netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks Condition="'$(TargetFrameworks)' == ''">net472;netcoreapp3.1</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private void ValidateAssembly(Package package, string filePath, string expectedA

assembly.FullName.ShouldBe(expectedAssemblyFullName);

assembly.GetTypes().ShouldHaveSingleItem().FullName.ShouldBe(expectedTypeFullName);
assembly.GetTypes().ShouldContain(i => i.FullName.Equals(expectedTypeFullName));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// Licensed under the MIT license.

using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Exceptions;
using Shouldly;
Expand All @@ -10,7 +11,7 @@

namespace Microsoft.Build.Utilities.ProjectCreation.UnitTests
{
public class ProjectTests : MSBuildTestBase
public class ProjectTests : TestBase
{
[Fact]
public void ProjectInstanceGetsCorrectObject()
Expand Down Expand Up @@ -77,10 +78,12 @@ public void ProjectWithGlobalPropertiesFromProjectCollection()
[Fact]
public void TryGetProjectBuildOutput()
{
ProjectRootElement import = ProjectCreator.Create()
.Save(GetTempProjectPath());

ProjectCreator.Create()
.Property("ImportDirectoryBuildTargets", "false")
.Import(@"$(MSBuildBinPath)\Microsoft.Common.targets")
.Import(@"$(MSBuildBinPath)\Microsoft.Common.targets")
.Import(import.FullPath)
.Import(import.FullPath)
.TryGetProject(out Project _, out BuildOutput buildOutput);

buildOutput.WarningEvents.ShouldHaveSingleItem(buildOutput.GetConsoleLog()).Code.ShouldBe("MSB4011", buildOutput.GetConsoleLog());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,36 @@ public abstract class TestBase : MSBuildTestBase, IDisposable
protected TestBase()
{
TestRootPath = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())).FullName;
WriteGlobalJson();
}

public string DotNetSdkVersion
{
get =>
#if NETCOREAPP3_1
"3.1.100";
#elif NET6_0
"6.0.100";
#elif NET7_0 || NETFRAMEWORK
"7.0.100";
#else
Unknown target framework!
#endif
}

public string TargetFramework
{
get =>
#if NETCOREAPP3_1
"netcoreapp3.1";
#elif NET5_0
"net5.0";
#elif NET6_0
"net6.0";
#else
#elif NET7_0
"net7.0";
#elif NETFRAMEWORK
"net472";
#else
Unknown target framework!
#endif
}

Expand Down Expand Up @@ -61,5 +78,17 @@ protected string GetTempProjectPath(string extension = null)

return Path.Combine(tempDirectoryInfo.FullName, $"{Path.GetRandomFileName()}{extension ?? string.Empty}");
}

private void WriteGlobalJson()
{
File.WriteAllText(
Path.Combine(TestRootPath, "global.json"),
$@"{{
""sdk"": {{
""version"": ""{DotNetSdkVersion}"",
""rollForward"": ""latestMinor""
}}
}}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected BuildEventArgsCollection()
/// <summary>
/// Gets the error messages that were logged.
/// </summary>
public IReadOnlyCollection<string> Errors => _errorEvents.Select(i => i.Message).ToList();
public IReadOnlyCollection<string> Errors => _errorEvents.Select(i => i.Message).ToList()!;

/// <summary>
/// Gets the messages that were logged.
Expand All @@ -79,7 +79,7 @@ protected BuildEventArgsCollection()
/// <summary>
/// Gets the warning messages that were logged.
/// </summary>
public IReadOnlyCollection<string> Warnings => _warningEvents.Select(i => i.Message).ToList();
public IReadOnlyCollection<string> Warnings => _warningEvents.Select(i => i.Message).ToList()!;

/// <inheritdoc cref="IDisposable.Dispose" />
public virtual void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ internal BuildMessageCollection(BuildEventArgsCollection buildOutput)
/// <summary>
/// Gets the messages that were logged with <see cref="MessageImportance.High" />.
/// </summary>
public IReadOnlyCollection<string> High => _buildOutput.MessageEvents.High.Select(i => i.Message).ToList();
public IReadOnlyCollection<string> High => _buildOutput.MessageEvents.High.Select(i => i.Message).ToList()!;

/// <summary>
/// Gets the messages that were logged with <see cref="MessageImportance.Low" />.
/// </summary>
public IReadOnlyCollection<string> Low => _buildOutput.MessageEvents.Low.Select(i => i.Message).ToList();
public IReadOnlyCollection<string> Low => _buildOutput.MessageEvents.Low.Select(i => i.Message).ToList()!;

/// <summary>
/// Gets the messages that were logged with <see cref="MessageImportance.Normal" />.
/// </summary>
public IReadOnlyCollection<string> Normal => _buildOutput.MessageEvents.Normal.Select(i => i.Message).ToList();
public IReadOnlyCollection<string> Normal => _buildOutput.MessageEvents.Normal.Select(i => i.Message).ToList()!;

/// <inheritdoc cref="IEnumerable{T}.GetEnumerator" />
public IEnumerator<string> GetEnumerator()
Expand Down
8 changes: 7 additions & 1 deletion src/Microsoft.Build.Utilities.ProjectCreation/BuildOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ private void OnAnyEventRaised(object sender, BuildEventArgs e)

private void OnBuildFinished(object sender, BuildFinishedEventArgs args) => _buildFinished = args;

private void OnProjectFinished(object sender, ProjectFinishedEventArgs e) => _resultsByProject.AddOrUpdate(e.ProjectFile, e.Succeeded, (projectFile, succeeded) => succeeded && e.Succeeded);
private void OnProjectFinished(object sender, ProjectFinishedEventArgs e)
{
if (e.ProjectFile != null)
{
_resultsByProject.AddOrUpdate(e.ProjectFile, e.Succeeded, (projectFile, succeeded) => succeeded && e.Succeeded);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static partial class MSBuildAssemblyResolver
}

AssemblyName candidateAssemblyName = AssemblyName.GetAssemblyName(candidateAssemblyFile.FullName);

#if !NET7_0_OR_GREATER
if (requestedAssemblyName.ProcessorArchitecture != System.Reflection.ProcessorArchitecture.None && requestedAssemblyName.ProcessorArchitecture != candidateAssemblyName.ProcessorArchitecture)
{
// The requested assembly has a processor architecture and the candidate assembly has a different value
Expand All @@ -67,6 +67,7 @@ public static partial class MSBuildAssemblyResolver
// Requested assembly has a public key but it doesn't match the candidate assembly public key
return null;
}
#endif

return assemblyLoader(candidateAssemblyFile.FullName);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks>net472;netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<ArtifactsPath>..\..\artifacts\$(MSBuildProjectName)</ArtifactsPath>
Expand Down Expand Up @@ -30,7 +30,6 @@
<PackageReference Include="Microsoft.Build.Utilities.Core" ExcludeAssets="Runtime" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.SDK.EmbedInteropTypes" Condition="'$(TargetFramework)' == 'net472'" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Setup.Configuration.Interop" Condition="'$(TargetFramework)' == 'net472'" ExcludeAssets="Runtime" PrivateAssets="All" />
<PackageReference Include="NuGet.Frameworks" ExcludeAssets="Compile" />
<PackageReference Include="System.ValueTuple" VersionOverride="4.5.0" Condition="'$(TargetFramework)' == 'net472'" ExcludeAssets="Compile" />
Expand Down
Loading

0 comments on commit 247cbc0

Please sign in to comment.