Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ env:
BuildPlatform: 'Any CPU'
ContinuousIntegrationBuild: 'true'
DotNet8Version: '8.x'
DotNet9Version: '9.x'
DotNet10Version: '10.x'

jobs:
BuildAndTest:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
os: [windows-2025, windows-2025-vs2026, ubuntu-latest, macos-latest]
include:
- os: windows-latest
name: Windows
- os: windows-2025
name: Windows VS2022
- os: windows-2025-vs2026
name: Windows VS2026
- os: ubuntu-latest
name: Linux
- os: macos-latest
Expand All @@ -43,26 +44,22 @@ jobs:
with:
fetch-depth: 0

- name: Install .NET ${{ env.DotNet8Version }}, ${{ env.DotNet9Version }}, and ${{ env.DotNet10Version }}
- name: Install .NET ${{ env.DotNet8Version }} and ${{ env.DotNet10Version }}
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
${{ env.DotNet8Version }}
${{ env.DotNet9Version }}
${{ env.DotNet10Version }}

- 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.name == 'Windows' }}
if: ${{ matrix.name == 'Windows VS2022' || matrix.name == 'Windows VS2026' }}
run: dotnet test --no-restore --no-build --framework net472 "/Property:Platform=${{ env.BuildPlatform }};Configuration=${{ env.BuildConfiguration }}" "/BinaryLogger:${{ env.ArtifactsDirectoryName }}/test-net472.binlog"

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

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

- name: Run Unit Tests (.NET 10)
run: dotnet test --no-restore --no-build --framework net10.0 "/Property:Platform=${{ env.BuildPlatform }};Configuration=${{ env.BuildConfiguration }}" "/BinaryLogger:${{ env.ArtifactsDirectoryName }}/test-net10.0.binlog"
Expand Down
16 changes: 10 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,32 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<MicrosoftBuildPackageVersion>18.0.2</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion>18.6.3</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion Condition="'$(TargetFramework)' == 'net8.0'">17.11.48</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion Condition="'$(TargetFramework)' == 'net9.0'">17.14.28</MicrosoftBuildPackageVersion>
<MicrosoftCodeAnalysisCSharpVersion>5.3.0</MicrosoftCodeAnalysisCSharpVersion>
<MicrosoftCodeAnalysisCSharpVersion Condition="'$(TargetFramework)' == 'net8.0'">4.13.0</MicrosoftCodeAnalysisCSharpVersion>
<SystemCodeDomVersion>10.0.8</SystemCodeDomVersion>
<SystemCodeDomVersion Condition="'$(TargetFramework)' == 'net8.0'">8.0.0</SystemCodeDomVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="AssemblyShader" Version="1.1.3" />
<PackageVersion Include="Microsoft.Build" Version="$(MicrosoftBuildPackageVersion)" />
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisCSharpVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="4.14.0" />
<PackageVersion Include="Microsoft.IO.Redist" Version="6.1.3" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.5.1" />
<PackageVersion Include="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="3.14.2075" />
<PackageVersion Include="Microsoft.VisualStudio.SolutionPersistence" Version="1.0.52" />
<PackageVersion Include="Shouldly" Version="4.3.0" />
<PackageVersion Include="System.IO.Compression" Version="4.3.0" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="System.CodeDom" Version="$(SystemCodeDomVersion)" />
<PackageVersion Include="xunit.v3" Version="3.2.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="Microsoft.Build.Artifacts" Version="6.1.63" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.300" />
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.9.50" />
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
<Compile Include="..\Shared\GlobalSuppressions.cs" />
Expand Down
5 changes: 2 additions & 3 deletions MSBuildProjectCreator.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32516.85
# Visual Studio Version 18
VisualStudioVersion = 18.5.11523.13 main
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.Utilities.ProjectCreation", "src\Microsoft.Build.Utilities.ProjectCreation\Microsoft.Build.Utilities.ProjectCreation.csproj", "{0CCB62BE-922F-480F-B8EA-823CB8A9CBDC}"
EndProject
Expand All @@ -22,7 +22,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{8339FD67
NuGet.config = NuGet.config
README.md = README.md
version.json = version.json
xunit.runner.json = xunit.runner.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{3F239E9A-CEB8-410A-BA63-4F860B9566E6}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,12 @@ public void CanRestoreAndBuild()
[Fact]
public void CanRestoreAndBuildMultipleTimes()
{
ProjectCreator projectCreator = ProjectCreator.Templates.SdkCsproj(
path: GetTempFileName(".csproj"),
targetFramework: TargetFramework)
ProjectCreator projectCreator = ProjectCreator.Create(
path: GetTempFileName(".csproj"))
.Target("Restore")
.TaskMessage("Restoring...", MessageImportance.High)
.Target("Build")
.TaskMessage("Building...", MessageImportance.High)
.Save()
.TryBuild(restore: true, "Build", out bool result, out BuildOutput buildOutput);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;net8.0;net9.0;net10.0</TargetFrameworks>
<TargetFrameworks>net472;net8.0;net10.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
</PropertyGroup>
<Import Project="..\Microsoft.Build.Utilities.ProjectCreation\build\MSBuild.ProjectCreation.props" Condition="'$(TargetFramework)' == 'net472'" />
<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AssemblyShader" />
<PackageReference Include="Microsoft.NET.Test.Sdk" ShadeDependencies="NuGet.Frameworks" />
<PackageReference Include="Shouldly" />
<PackageReference Include="System.CodeDom" VersionOverride="9.0.0" Condition="'$(TargetFramework)' == 'net9.0'" ExcludeAssets="All" />
<PackageReference Include="System.CodeDom" VersionOverride="10.0.0" Condition="'$(TargetFramework)' == 'net10.0'" ExcludeAssets="All" />
<PackageReference Include="xunit" />
<PackageReference Include="System.CodeDom" Condition="'$(TargetFramework)' == 'net8.0' Or '$(TargetFramework)' == 'net10.0'" ExcludeAssets="Runtime" />
<PackageReference Include="xunit.v3" />
<PackageReference Include="xunit.runner.visualstudio" />
</ItemGroup>
<ItemGroup>
Expand All @@ -22,4 +19,10 @@
<ItemGroup>
<ProjectReference Include="..\Microsoft.Build.Utilities.ProjectCreation\Microsoft.Build.Utilities.ProjectCreation.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
<PackageReference Include="System.Text.Json" VersionOverride="10.0.3" />
<PackageReference Include="System.Text.Encodings.Web" VersionOverride="10.0.3" />

<SuggestedBindingRedirects Include="System.Text.Encodings.Web, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" MaxVersion="10.0.0.3" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ namespace Microsoft.Build.Utilities.ProjectCreation.UnitTests
public class SdkCsprojTests : TestBase
{
[Fact]
public void CanBuild()
public void CanRestoreAndBuild()
{
ProjectCreator.Templates.SdkCsproj(
targetFramework: TargetFramework,
path: GetTempFileName(".csproj"))
.Save()
.TryBuild(restore: true, "Build", out bool result, out BuildOutput buildOutput);
targetFramework: TargetFramework,
path: GetTempFileName(".csproj"))
.Save()
.TryBuild(restore: true, "Build", out bool result, out BuildOutput buildOutput);

result.ShouldBeTrue(buildOutput.GetConsoleLog());
}
Expand Down
39 changes: 21 additions & 18 deletions src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,17 @@ protected TestBase()
WriteGlobalJson();
}

public string DotNetSdkVersion
{
get =>
#if NET8_0 || NETFRAMEWORK
"8.0.100";
#elif NET9_0 || NETFRAMEWORK
"9.0.100";
#elif NET10_0 || NETFRAMEWORK
"10.0.100";
#else
#error Unknown target framework!
#endif
}

public string TargetFramework
{
get =>
#if NET8_0
"net8.0";
#elif NET9_0
"net9.0";
#elif NET10_0
"net10.0";
#elif NETFRAMEWORK
"net472";
#else
#error Unknown target framework!
#error Unknown target framework!
#endif
}

Expand Down Expand Up @@ -85,10 +69,29 @@ private void WriteGlobalJson()
Path.Combine(TestRootPath, "global.json"),
$@"{{
""sdk"": {{
""version"": ""{DotNetSdkVersion}"",
""version"": ""{GetDotNetSdkVersionString()}"",
""rollForward"": ""latestMinor""
}}
}}");
string GetDotNetSdkVersionString()
{
#if NET8_0
return "8.0.100";
#elif NET10_0
return "10.0.100";
#elif NETFRAMEWORK
System.Diagnostics.FileVersionInfo fileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(MSBuildAssemblyResolver.MSBuildExePath);

return fileVersionInfo.FileMajorPart switch
{
17 => "8.0.100",
18 => "10.0.100",
_ => throw new InvalidOperationException($"Unexpected MSBuild version: {fileVersionInfo.FileMajorPart}"),
};
#else
#error Unknown target framework!
#endif
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public abstract class BuildEventArgsCollection : IDisposable
private string? _lastConsoleOutput = null;

/// <summary>
/// Stores the <see cref="LoggerVerbosity" /> of the last console output.
/// Stores the parameters used to generate the last console output for cache invalidation.
/// </summary>
private LoggerVerbosity _lastVerbosity = LoggerVerbosity.Normal;
private (LoggerVerbosity Verbosity, bool ShowSummary, bool PerformanceSummary, bool ErrorsOnly, bool WarningsOnly, bool ShowItemAndPropertyList, bool ShowCommandLine, bool ShowTimestamp, bool ShowEventId) _lastConsoleLogParameters;

/// <summary>
/// Initializes a new instance of the <see cref="BuildEventArgsCollection" /> class.
Expand Down Expand Up @@ -120,12 +120,14 @@ public virtual void Dispose()
/// <returns>The build output in the format of a console log.</returns>
public string GetConsoleLog(LoggerVerbosity verbosity = LoggerVerbosity.Normal, bool showSummary = true, bool performanceSummary = false, bool errorsOnly = false, bool warningsOnly = false, bool showItemAndPropertyList = true, bool showCommandLine = false, bool showTimestamp = false, bool showEventId = false)
{
if (_lastConsoleOutput != null && verbosity == _lastVerbosity)
var currentParameters = (verbosity, showSummary, performanceSummary, errorsOnly, warningsOnly, showItemAndPropertyList, showCommandLine, showTimestamp, showEventId);

if (_lastConsoleOutput != null && currentParameters == _lastConsoleLogParameters)
{
return _lastConsoleOutput;
}

_lastVerbosity = verbosity;
_lastConsoleLogParameters = currentParameters;

_lastConsoleOutput = ConsoleLoggerStringBuilder.GetConsoleLogAsString(AllEvents, verbosity, showSummary, performanceSummary, errorsOnly, warningsOnly, showItemAndPropertyList, showCommandLine, showTimestamp, showEventId);

Expand Down
12 changes: 1 addition & 11 deletions src/Microsoft.Build.Utilities.ProjectCreation/BuildHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,7 @@ private static bool BuildProjectFromFullPath(
throw buildResult.Exception;
}

if (targetOutputs != null)
{
foreach (KeyValuePair<string, TargetResult> targetResult in buildResult.ResultsByTarget)
{
targetOutputs[targetResult.Key] = targetResult.Value;
}
}
else
{
targetOutputs = buildResult.ResultsByTarget;
}
targetOutputs = buildResult.ResultsByTarget;

return buildResult.OverallResult == BuildResultCode.Success;

Expand Down
Loading
Loading