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
9 changes: 6 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
BuildAndTest:
strategy:
matrix:
os: [windows-2025, windows-2025-vs2026, ubuntu-latest, macos-latest]
os: [windows-2022, windows-2025-vs2026, ubuntu-latest, macos-latest]
include:
- os: windows-2025
- os: windows-2022
name: Windows VS2022
- os: windows-2025-vs2026
name: Windows VS2026
Expand All @@ -52,16 +52,19 @@ jobs:
${{ env.DotNet10Version }}

- name: Build Solution
id: build
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 VS2022' || matrix.name == 'Windows VS2026' }}
if: ${{ startsWith(matrix.name, 'Windows') && !cancelled() && steps.build.outcome == 'success' }}
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)
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
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 10)
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: dotnet test --no-restore --no-build --framework net10.0 "/Property:Platform=${{ env.BuildPlatform }};Configuration=${{ env.BuildConfiguration }}" "/BinaryLogger:${{ env.ArtifactsDirectoryName }}/test-net10.0.binlog"

- name: Upload Artifacts
Expand Down
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
<ItemGroup>
<PackageVersion Include="AssemblyShader" Version="1.1.3" />
<PackageVersion Include="Microsoft.Build" Version="$(MicrosoftBuildPackageVersion)" />
<PackageVersion Include="Microsoft.Build.Framework" Version="$(MicrosoftBuildPackageVersion)" />
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildPackageVersion)" />
<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.5.1" />
<PackageVersion Include="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="3.14.2075" />
<PackageVersion Include="Microsoft.VisualStudio.SolutionPersistence" Version="1.0.52" />
<PackageVersion Include="MSBuild.StructuredLogger" Version="2.3.204" />
<PackageVersion Include="Shouldly" Version="4.3.0" />
<PackageVersion Include="System.IO.Compression" Version="4.3.0" />
<PackageVersion Include="System.CodeDom" Version="$(SystemCodeDomVersion)" />
Expand Down
62 changes: 0 additions & 62 deletions MSBuildProjectCreator.sln

This file was deleted.

26 changes: 26 additions & 0 deletions MSBuildProjectCreator.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Solution>
<Folder Name="/.github/">
<File Path=".github/dependabot.yml" />
</Folder>
<Folder Name="/.github/workflows/">
<File Path=".github/workflows/CI.yml" />
<File Path=".github/workflows/Official.yml" />
</Folder>
<Folder Name="/build/">
<File Path=".gitattributes" />
<File Path=".gitignore" />
<File Path="CONTRIBUTING.md" />
<File Path="Directory.Build.props" />
<File Path="Directory.Build.rsp" />
<File Path="Directory.Packages.props" />
<File Path="Directory.Solution.props" />
<File Path="global.json" />
<File Path="key.snk" />
<File Path="LICENSE" />
<File Path="NuGet.config" />
<File Path="README.md" />
<File Path="version.json" />
</Folder>
<Project Path="src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/Microsoft.Build.Utilities.ProjectCreation.UnitTests.csproj" />
<Project Path="src/Microsoft.Build.Utilities.ProjectCreation/Microsoft.Build.Utilities.ProjectCreation.csproj" />
</Solution>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Jeff Kluge. All rights reserved.
// Copyright (c) Jeff Kluge. All rights reserved.
//
// Licensed under the MIT license.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Jeff Kluge. All rights reserved.
// Copyright (c) Jeff Kluge. All rights reserved.
//
// Licensed under the MIT license.

Expand Down Expand Up @@ -127,7 +127,7 @@ public void OverallResult(bool succeeded)
[Fact]
public void ResultsByProject()
{
Dictionary<string, bool> projects = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase)
Dictionary<string, bool> projects = new(StringComparer.OrdinalIgnoreCase)
{
{ Path.Combine("DA920698", "E40D", "4D8F", "89D8", "B85D870C4214"), true },
{ Path.Combine("53C78698", "F360", "491F", "8025", "B323782DD912"), false },
Expand All @@ -154,7 +154,7 @@ public void Warnings(string expectedMessage, string expectedCode)

private BuildOutput GetProjectLoggerWithEvents(Action<MockEventSource> eventSourceActions)
{
MockEventSource eventSource = new MockEventSource();
MockEventSource eventSource = new();

BuildOutput buildOutput = BuildOutput.Create();

Expand All @@ -165,4 +165,4 @@ private BuildOutput GetProjectLoggerWithEvents(Action<MockEventSource> eventSour
return buildOutput;
}
}
}
}
104 changes: 88 additions & 16 deletions src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildTests.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Copyright (c) Jeff Kluge. All rights reserved.
// Copyright (c) Jeff Kluge. All rights reserved.
//
// Licensed under the MIT license.

using Microsoft.Build.Evaluation;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Logging;
using Microsoft.Build.Logging.StructuredLogger;
using Shouldly;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Xunit;

namespace Microsoft.Build.Utilities.ProjectCreation.UnitTests
Expand All @@ -36,16 +36,88 @@ public void BasicBuild()
result3.ShouldBeTrue();
}

[Fact]
public void BinaryLogContainsNuGetGeneratedFiles()
{
string binLogPath = Path.Combine(TestRootPath, "test.binlog");
string projectPath = Path.Combine(TestRootPath, "ClassLibraryA", "ClassLibraryA.csproj");

using (PackageRepository.Create(TestRootPath)
.Package("PackageA", "1.0.0", out Package packageA)
.Library(TargetFramework))
{
string projectExtensionsPath;

using (ProjectCollection projectCollection = new ProjectCollection())
{
projectCollection.RegisterLogger(new Logging.BinaryLogger
{
Parameters = $"LogFile={binLogPath}",
});

ProjectCreator.Templates.SdkCsproj(
path: projectPath,
targetFramework: TargetFramework,
projectCollection: projectCollection)
.ItemPackageReference(packageA)
.TryBuild(restore: true, out bool result, out BuildOutput buildOutput)
.TryGetPropertyValue("MSBuildProjectExtensionsPath", out projectExtensionsPath);

result.ShouldBeTrue(buildOutput.GetConsoleLog());
}

Logging.StructuredLogger.Build binaryLog = BinaryLog.ReadBuild(binLogPath);

binaryLog.SourceFiles.ShouldContain(i => i.FullPath.Equals(Path.Combine(projectExtensionsPath, "ClassLibraryA.csproj.nuget.g.props")));
}
}

[Fact]
public void BuildCanConsumePackageWithGeneratePathProperty()
{
string projectPath = Path.Combine(TestRootPath, "ClassLibraryA", "ClassLibraryA.csproj");

using (PackageRepository.Create(TestRootPath)
.Package("PackageB", "1.0", out Package packageB)
.Library(TargetFramework)
.Package("PackageA", "1.0.0", out Package packageA)
.Dependency(packageB, TargetFramework)
.Library(TargetFramework))
{
string projectExtensionsPath;

using ProjectCollection projectCollection = new ProjectCollection();

ProjectCreator.Templates.SdkCsproj(
path: projectPath,
targetFramework: TargetFramework,
projectCollection: projectCollection)
.ItemPackageReference(
packageA,
metadata: new Dictionary<string, string?>
{
["GeneratePathProperty"] = bool.TrueString,
})
.TryBuild(restore: true, out bool result, out BuildOutput buildOutput)
.TryGetPropertyValue("PkgPackageA", out string packagePath)
.TryGetPropertyValue("MSBuildProjectExtensionsPath", out projectExtensionsPath);

result.ShouldBeTrue(buildOutput.GetConsoleLog());

packagePath.ShouldEndWith(Path.Combine(".nuget", "packages", "packagea", "1.0.0"));
}
}

[Fact]
public void BuildOutputContainsOutOfProcMessages()
{
const int messageCount = 100;

List<ProjectCreator> projects = new List<ProjectCreator>(messageCount);
List<ProjectCreator> projects = new(messageCount);

for (int i = 0; i < messageCount; i++)
{
FileInfo projectPath = new FileInfo(Path.Combine(TestRootPath, $"Project{i}", $"Project{i}.proj"));
FileInfo projectPath = new(Path.Combine(TestRootPath, $"Project{i}", $"Project{i}.proj"));

projectPath.Directory!.Create();

Expand Down Expand Up @@ -112,7 +184,7 @@ public void BuildTargetOutputsTest()
[Fact]
public void BuildWithGlobalProperties()
{
Dictionary<string, string> globalProperties = new Dictionary<string, string>
Dictionary<string, string> globalProperties = new()
{
["Property1"] = "D7BBABDFB2D142D3A75E0C1A33E33780",
};
Expand All @@ -138,7 +210,7 @@ public void CanBuildLotsOfProjects()
{
int maxBuilds = Environment.ProcessorCount * 2;

List<ProjectCreator> projects = new List<ProjectCreator>(maxBuilds);
List<ProjectCreator> projects = new(maxBuilds);

for (int i = 0; i < maxBuilds; i++)
{
Expand Down Expand Up @@ -210,9 +282,9 @@ public void ProjectCollectionLoggersWork()
string binLogPath = Path.Combine(TestRootPath, "test.binlog");
string fileLogPath = Path.Combine(TestRootPath, "test.log");

using (ProjectCollection projectCollection = new ProjectCollection())
using (ProjectCollection projectCollection = new())
{
projectCollection.RegisterLogger(new BinaryLogger
projectCollection.RegisterLogger(new Logging.BinaryLogger
{
Parameters = $"LogFile={binLogPath}",
});
Expand Down Expand Up @@ -251,9 +323,9 @@ public void ProjectCollectionLoggersWorkWithRestore()
string binLogPath = Path.Combine(TestRootPath, "test.binlog");
string fileLogPath = Path.Combine(TestRootPath, "test.log");

using (ProjectCollection projectCollection = new ProjectCollection())
using (ProjectCollection projectCollection = new())
{
projectCollection.RegisterLogger(new BinaryLogger
projectCollection.RegisterLogger(new Logging.BinaryLogger
{
Parameters = $"LogFile={binLogPath}",
});
Expand Down Expand Up @@ -294,7 +366,7 @@ public void ProjectCollectionLoggersWorkWithRestore()
[Fact]
public void ProjectWithGlobalPropertiesUsedDuringBuild()
{
ProjectCollection projectCollection = new ProjectCollection(new Dictionary<string, string>
ProjectCollection projectCollection = new(new Dictionary<string, string>
{
["Property1"] = "F6EBAC88A10E453B9AF8FA656A574737",
});
Expand Down Expand Up @@ -323,7 +395,7 @@ public void ProjectWithNoPathRestoreThrowsInvalidOperationException()
[Fact]
public void RestoreAndBuildUseDifferentGlobalPropertiesWhenGlobalPropertiesSpecified()
{
Dictionary<string, string> globalProperties = new Dictionary<string, string>
Dictionary<string, string> globalProperties = new()
{
["Something"] = bool.TrueString,
};
Expand Down Expand Up @@ -351,12 +423,12 @@ public void RestoreAndBuildUseDifferentGlobalPropertiesWhenGlobalPropertiesSpeci
[Fact]
public void RestoreAndBuildUseDifferentGlobalPropertiesWhenProjectCollectionSpecified()
{
Dictionary<string, string> globalProperties = new Dictionary<string, string>
Dictionary<string, string> globalProperties = new()
{
["Something"] = bool.TrueString,
};

using ProjectCollection projectCollection = new ProjectCollection(globalProperties);
using ProjectCollection projectCollection = new(globalProperties);

ProjectCreator.Create(
path: GetTempFileName(".csproj"),
Expand Down Expand Up @@ -397,7 +469,7 @@ public void RestoreTargetCanBeRun()
[Fact]
public void RestoreUsesGlobalPropertiesFromCreate()
{
Dictionary<string, string> globalProperties = new Dictionary<string, string>
Dictionary<string, string> globalProperties = new()
{
["SomeGlobalProperty"] = "04BB4AFE8AE14B7A8E3511B5F2CD442B",
};
Expand All @@ -416,4 +488,4 @@ public void RestoreUsesGlobalPropertiesFromCreate()
buildOutput.MessageEvents.High.ShouldContain(i => i.Message == "04BB4AFE8AE14B7A8E3511B5F2CD442B" && i.Importance == MessageImportance.High, buildOutput.GetConsoleLog());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Jeff Kluge. All rights reserved.
// Copyright (c) Jeff Kluge. All rights reserved.
//
// Licensed under the MIT license.

Expand Down Expand Up @@ -290,4 +290,4 @@ public void WhenPropertyThowsIfNoWhen()
.ShouldBe("You must add a When before adding a When PropertyGroup.");
}
}
}
}
Loading