Skip to content
Open
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
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<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
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.");
}
}
}
}
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 @@ -43,4 +43,4 @@ public void CustomTemplate()
StringCompareShould.IgnoreLineEndings);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (c) Jeff Kluge. All rights reserved.
// Copyright (c) Jeff Kluge. All rights reserved.
//
// Licensed under the MIT license.

using Shouldly;
using System.IO;
using System.Xml.Linq;

namespace Microsoft.Build.Utilities.ProjectCreation.UnitTests
{
Expand All @@ -30,4 +29,4 @@ public static DirectoryInfo ShouldExist(this DirectoryInfo directoryInfo)
return directoryInfo;
}
}
}
}
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 @@ -169,4 +169,4 @@ public void ImportWithConditionOnExistence()
StringCompareShould.IgnoreLineEndings);
}
}
}
}
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 @@ -55,4 +55,4 @@ public void ItemGroupSimple()
StringCompareShould.IgnoreLineEndings);
}
}
}
}
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 @@ -372,4 +372,4 @@ public void UpdateItem()
StringCompareShould.IgnoreLineEndings);
}
}
}
}
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 @@ -35,4 +35,4 @@ public void ForEachItems()
StringCompareShould.IgnoreLineEndings);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="AssemblyShader" />
<PackageReference Include="Microsoft.NET.Test.Sdk" ShadeDependencies="NuGet.Frameworks" />
<PackageReference Include="MSBuild.StructuredLogger" />
<PackageReference Include="Shouldly" />
<PackageReference Include="System.CodeDom" Condition="'$(TargetFramework)' == 'net8.0' Or '$(TargetFramework)' == 'net10.0'" ExcludeAssets="Runtime" />
<PackageReference Include="xunit.v3" />
Expand Down
Loading
Loading