Skip to content

Commit

Permalink
Add support for net9.0 (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyGerlicher authored Sep 24, 2024
1 parent c9b35dd commit 18d9956
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 48 deletions.
5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@
<UseArtifactsOutput>false</UseArtifactsOutput>
<IsTestProject Condition="$(MSBuildProjectName.EndsWith('UnitTests'))">true</IsTestProject>
<IsPackable Condition="'$(IsTestProject)' != 'true'">true</IsPackable>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
<UseArtifactsOutput>false</UseArtifactsOutput>

<!-- Suppress spam about using a preview version of .NET -->
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
</PropertyGroup>
</Project>
29 changes: 17 additions & 12 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<MicrosoftBuildPackageVersion Condition="'$(TargetFramework)' == 'netstandard2.0'">16.9.0</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion Condition="'$(TargetFramework)' == 'net46'">15.9.20</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion Condition="'$(TargetFramework)' == 'net8.0'">17.7.2</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion>17.8.3</MicrosoftBuildPackageVersion>

<!-- Please use caution adding a dependency to MSBuild packages. Use latest for testing and
use the minimum version for compilation for back compat. -->
<MicrosoftBuildPackageVersion>17.11.4</MicrosoftBuildPackageVersion>
<MicrosoftBuildMinimumPackageVersion>16.11.0</MicrosoftBuildMinimumPackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="CopyOnWrite" Version="0.3.11" Condition=" '$(TargetFramework)' != 'net46' " />
Expand All @@ -13,21 +14,25 @@
<PackageVersion Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="System.CodeDom" Version="8.0.0" />
<PackageVersion Include="System.Collections.Immutable" Version="7.0.0" />
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.4" />
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="7.0.0" Condition=" '$(TargetFramework)' != 'net46' " />
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="4.11.1" Condition=" '$(TargetFramework)' == 'net46' " />
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="8.0.1" />

<!-- Pinning vulnerable packages -->
<PackageVersion Include="System.Security.Cryptography.Xml" Version="8.0.1" />
<PackageVersion Include="Microsoft.IO.Redist" Version="6.0.1" />
<PackageVersion Include="System.Formats.Asn1" Version="8.0.1" />
</ItemGroup>
<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<PackageVersion Include="AssemblyShader" Version="1.0.3-preview" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="MSBuild.ProjectCreation" Version="10.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="MSBuild.ProjectCreation" Version="13.0.0" />
<PackageVersion Include="Shouldly" Version="4.2.1" />
<PackageVersion Include="xunit" Version="2.7.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
<PackageVersion Include="xunit" Version="2.9.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="Microsoft.Build.Artifacts" Version="6.1.10" Condition="'$(EnableArtifacts)' != 'false'" />
<GlobalPackageReference Include="Microsoft.Build.Artifacts" Version="6.1.30" Condition="'$(EnableArtifacts)' != 'false'" />
<GlobalPackageReference Include="Microsoft.VisualStudioEng.MicroBuild.Core" Version="1.0.0" Condition="'$(EnableMicroBuild)' != 'false'" />
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" Condition="'$(EnableGitVersioning)' != 'false'" />
</ItemGroup>
Expand Down
43 changes: 43 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ variables:
BuildConfiguration: 'Debug'
BuildPlatform: 'Any CPU'
DotNet8Version: '8.x'
DotNet9Version: '9.x'
MSBuildArgs: '"/p:Platform=$(BuildPlatform)" "/p:Configuration=$(BuildConfiguration)" "/BinaryLogger:$(Build.SourcesDirectory)\$(ArtifactsDirectoryName)\msbuild.binlog"'
SignType: 'Test'

Expand Down Expand Up @@ -39,6 +40,12 @@ jobs:
inputs:
version: '$(DotNet8Version)'

- task: UseDotNet@2
displayName: 'Install .NET $(DotNet9Version)'
inputs:
version: '$(DotNet9Version)'
includePreviewVersions: true

- task: DotNetCoreCLI@2
displayName: 'Build Solution'
inputs:
Expand All @@ -61,6 +68,14 @@ jobs:
testRunTitle: 'Windows .NET 8.0'
condition: succeededOrFailed()

- task: DotNetCoreCLI@2
displayName: 'Run Unit Tests (.NET 9.0)'
inputs:
command: 'test'
arguments: '--no-restore --no-build --framework net9.0 /noautorsp'
testRunTitle: 'Windows .NET 9.0'
condition: succeededOrFailed()

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifacts'
inputs:
Expand All @@ -79,6 +94,12 @@ jobs:
inputs:
version: '$(DotNet8Version)'

- task: UseDotNet@2
displayName: 'Install .NET $(DotNet9Version)'
inputs:
version: '$(DotNet9Version)'
includePreviewVersions: true

- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
Expand All @@ -93,6 +114,14 @@ jobs:
testRunTitle: 'Linux .NET 8.0'
condition: succeededOrFailed()

- task: DotNetCoreCLI@2
displayName: 'Run Unit Tests (.NET 9.0)'
inputs:
command: 'test'
arguments: '--no-restore --no-build --framework net9.0 /noautorsp'
testRunTitle: 'Linux .NET 9.0'
condition: succeededOrFailed()

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifacts'
inputs:
Expand All @@ -111,6 +140,12 @@ jobs:
inputs:
version: '$(DotNet8Version)'

- task: UseDotNet@2
displayName: 'Install .NET $(DotNet9Version)'
inputs:
version: '$(DotNet9Version)'
includePreviewVersions: true

- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
Expand All @@ -125,6 +160,14 @@ jobs:
testRunTitle: 'MacOS .NET 8.0'
condition: succeededOrFailed()

- task: DotNetCoreCLI@2
displayName: 'Run Unit Tests (.NET 9.0)'
inputs:
command: 'test'
arguments: '--no-restore --no-build --framework net9.0 /noautorsp'
testRunTitle: 'MacOS .NET 9.0'
condition: succeededOrFailed()

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifacts'
inputs:
Expand Down
5 changes: 3 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"sdk": {
"version": "8.0.400",
"rollForward": "latestMinor"
"version": "9.0.100-rc.1.24452.12",
"rollForward": "latestMinor",
"allowPrerelease": true
},
"msbuild-sdks": {
"Microsoft.Build.NoTargets": "3.7.56"
Expand Down
2 changes: 1 addition & 1 deletion samples/NoTargets/SampleNoTargets/SampleNoTargets.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.Build.NoTargets/3.7.0">
<Project Sdk="Microsoft.Build.NoTargets/3.7.56">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;net8.0</TargetFrameworks>
<TargetFrameworks>net472;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AssemblyShader" />
Expand Down
13 changes: 5 additions & 8 deletions src/Artifacts/Microsoft.Build.Artifacts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
<Compile Include="..\Shared\CopyExceptionHandling.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CopyOnWrite"
GeneratePathProperty="True"
PrivateAssets="All" />
<PackageReference Include="Microsoft.Build.Tasks.Core"
ExcludeAssets="Runtime"
PrivateAssets="All" />
<PackageReference Include="System.Threading.Tasks.Dataflow"
PrivateAssets="All" />
<PackageReference Include="CopyOnWrite" GeneratePathProperty="True" PrivateAssets="All" />

<!-- Note these are API dependencies to support a minimum version of MSBuild. -->
<PackageReference Include="Microsoft.Build.Tasks.Core" VersionOverride="$(MicrosoftBuildMinimumPackageVersion)" ExcludeAssets="Runtime" PrivateAssets="All" />
<PackageReference Include="System.Threading.Tasks.Dataflow" VersionOverride="4.9.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<None Include="build\*"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;net8.0</TargetFrameworks>
<TargetFrameworks>net472;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.Build.NoTargets">
<PropertyGroup>
<TargetFrameworks>net40;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Description>Provides the ability to centrally manage your NuGet package versions when using PackageReference.</Description>
<PackageTags>MSBuild MSBuildSdk</PackageTags>
<ArtifactsPath>$(BaseArtifactsPath)\$(MSBuildProjectName)\</ArtifactsPath>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;net8.0</TargetFrameworks>
<TargetFrameworks>net472;net8.0;net9.0</TargetFrameworks>
<Nullable>Enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CopyOnWrite" />
<PackageReference Include="Microsoft.Build" Condition="'$(TargetFramework)' != 'net8.0' " />
<PackageReference Include="Microsoft.Build" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Microsoft.Win32.Registry" />
<PackageReference Include="MSBuild.ProjectCreation" />
Expand Down
2 changes: 2 additions & 0 deletions src/CopyOnWrite/Microsoft.Build.CopyOnWrite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
<PackageReference Include="CopyOnWrite"
GeneratePathProperty="True"
PrivateAssets="All" />
<!-- Note this is an API dependencies to support a minimum version of MSBuild. -->
<PackageReference Include="Microsoft.Build.Tasks.Core"
VersionOverride="$(MicrosoftBuildMinimumPackageVersion)"
PrivateAssets="all"
ExcludeAssets="Runtime"
IncludeAssets="compile; build; native; contentfiles; analyzers; buildtransitive" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;net8.0</TargetFrameworks>
<TargetFrameworks>net472;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AssemblyShader" />
<PackageReference Include="Microsoft.NET.Test.Sdk"
ShadeDependencies="NuGet.Frameworks" />
ShadeDependencies="NuGet.Frameworks" />
<PackageReference Include="MSBuild.ProjectCreation" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="Shouldly" />
Expand Down
72 changes: 58 additions & 14 deletions src/NoTargets.UnitTests/NoTargetsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public void DoNotReferenceOutputAssemblies()
path: Path.Combine(TestRootPath, "ProjectA", "ProjectA.csproj"),
#if NETFRAMEWORK || NET8_0
targetFramework: "net8.0")
#elif NET9_0
targetFramework: "net9.0")
#endif
.Save();

Expand Down Expand Up @@ -264,35 +266,76 @@ public void SimpleBuild(string projectExtension)
buildOutput.Messages.High.ShouldContain("86F00AF59170450E9D687652D74A6394");
}

[Theory]
#if !NETFRAMEWORK
[InlineData(".csproj")]
#endif
[InlineData(".proj", Skip = "Currently broken because of a regression in Static Graph when the extension is .proj")]
public void StaticGraphBuildsSucceed(string projectExtension)
[Fact]
public void StaticGraphBuildsSucceed()
{
ProjectCreator sdkReference = ProjectCreator.Templates.SdkCsproj(
Path.Combine(TestRootPath, "sdkstyle", "sdkstyle.csproj"))
.Save();

ProjectCreator noTargets = ProjectCreator.Templates.NoTargetsProject(
path: Path.Combine(TestRootPath, "notargets", "notargets.csproj"),
customAction: creator =>
{
creator.ItemProjectReference(sdkReference, referenceOutputAssembly: false);
}).Save();

ProjectCreator project = ProjectCreator.Templates.SdkCsproj(
Path.Combine(TestRootPath, "main", $"main.csproj"),
projectCreator: creator =>
{
creator.ItemProjectReference(noTargets, referenceOutputAssembly: false);
})
.Save()
.TryBuild("Restore", out bool result, out BuildOutput restoreOutput);

result.ShouldBeTrue(restoreOutput.GetConsoleLog());

using (BuildManager buildManager = new BuildManager())
using (ProjectCollection projectCollection = new ProjectCollection())
{
try
{
BuildOutput buildOutput = BuildOutput.Create();

buildManager.BeginBuild(
new BuildParameters(projectCollection)
{
Loggers = new[] { buildOutput },
IsolateProjects = true,
});
GraphBuildResult graphResult = buildManager.BuildRequest(
new GraphBuildRequestData(
[new ProjectGraphEntryPoint(project.FullPath, new Dictionary<string, string>())],
new List<string> { "Build" }));
var console = buildOutput.GetConsoleLog();
graphResult.OverallResult.ShouldBe(BuildResultCode.Success, graphResult.Exception?.ToString());
}
finally
{
buildManager.EndBuild();
}
}
}

#if NETFRAMEWORK
[Fact]
public void StaticGraphBuildsSucceedLegacyCsproj()
{
ProjectCreator legacyReference = ProjectCreator.Templates.LegacyCsproj(
Path.Combine(TestRootPath, "legacy", "legacy.csproj"),
targetFrameworkVersion: "v4.7.2")
.Save();
#endif

ProjectCreator noTargets = ProjectCreator.Templates.NoTargetsProject(
path: Path.Combine(TestRootPath, "notargets", "notargets.csproj"),
customAction: creator =>
{
creator.ItemProjectReference(sdkReference, referenceOutputAssembly: false);
#if NETFRAMEWORK
creator.ItemProjectReference(legacyReference, referenceOutputAssembly: false);
#endif
}).Save();

ProjectCreator project = ProjectCreator.Templates.SdkCsproj(
Path.Combine(TestRootPath, "main", $"main{projectExtension}"),
Path.Combine(TestRootPath, "main", $"main.csproj"),
projectCreator: creator =>
{
creator.ItemProjectReference(noTargets, referenceOutputAssembly: false);
Expand All @@ -318,17 +361,18 @@ public void StaticGraphBuildsSucceed(string projectExtension)

GraphBuildResult graphResult = buildManager.BuildRequest(
new GraphBuildRequestData(
new[] { new ProjectGraphEntryPoint(project.FullPath) },
new[] { "Build" }));
new[] { new ProjectGraphEntryPoint(project.FullPath, new Dictionary<string, string>()) },
new List<string> { "Build" }));

graphResult.OverallResult.ShouldBe(BuildResultCode.Success, buildOutput.GetConsoleLog());
graphResult.OverallResult.ShouldBe(BuildResultCode.Success, graphResult.Exception?.ToString());
}
finally
{
buildManager.EndBuild();
}
}
}
#endif

[Theory]
[InlineData(".csproj", "Build")]
Expand Down
2 changes: 1 addition & 1 deletion src/NoTargets/Microsoft.Build.NoTargets.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.Build.NoTargets">
<PropertyGroup>
<TargetFrameworks>net40;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Description>Provides targets for projects that do not compile an assembly.</Description>
<PackageTags>MSBuild MSBuildSdk notargets notarget</PackageTags>
<ArtifactsPath>$(BaseArtifactsPath)$(MSBuildProjectName)\</ArtifactsPath>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;net8.0</TargetFrameworks>
<TargetFrameworks>net472;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AssemblyShader" />
Expand Down
2 changes: 1 addition & 1 deletion src/Traversal.UnitTests/TraversalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ public void StaticGraphBuildAndRestoreSucceed()
targetsToBuild: new[] { "Restore" });

var graphBuildRequestData = new GraphBuildRequestData(
projectGraphEntryPoints: new[] { new ProjectGraphEntryPoint(traversalProject.FullPath) },
projectGraphEntryPoints: new[] { new ProjectGraphEntryPoint(traversalProject.FullPath, new Dictionary<string, string>()) },
targetsToBuild: new[] { "Build" });

var graphRestoreResult = buildManager.BuildRequest(graphRestoreRequestData);
Expand Down
Loading

0 comments on commit 18d9956

Please sign in to comment.