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
7 changes: 1 addition & 6 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ env:
BuildPlatform: 'Any CPU'
ContinuousIntegrationBuild: 'true'
DotNet8Version: '8.x'
DotNet9Version: '9.x'
DotNet10Version: '10.x'

jobs:
Expand All @@ -43,12 +42,11 @@ 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
Expand All @@ -61,9 +59,6 @@ jobs:
- 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
7 changes: 3 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<MicrosoftBuildPackageVersion>18.0.2</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion>18.3.3</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion Condition="'$(TargetFramework)' == 'net8.0'">17.11.48</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion Condition="'$(TargetFramework)' == 'net9.0'">17.14.28</MicrosoftBuildPackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="AssemblyShader" Version="1.1.3" />
Expand All @@ -18,12 +17,12 @@
<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="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.103" />
<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
@@ -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" VersionOverride="10.0.3" Condition="'$(TargetFramework)' == 'net10.0'" ExcludeAssets="All" />
<PackageReference Include="xunit.v3" />
<PackageReference Include="xunit.runner.visualstudio" />
</ItemGroup>
<ItemGroup>
Expand Down

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
80 changes: 0 additions & 80 deletions src/Microsoft.Build.Utilities.ProjectCreation/BuildManagerHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,8 @@ namespace Microsoft.Build.Utilities.ProjectCreation
/// </summary>
internal static class BuildManagerHost
{
/// <summary>
/// Gets a value indicating if the current runtime is .NET Core or .NET Framework.
/// </summary>
private static readonly Lazy<bool> IsDotNetCoreLazy = new Lazy<bool>(() => !RuntimeInformation.FrameworkDescription.Contains("Framework"));

private static readonly object LockObject = new object();

/// <summary>
/// Gets a value indicating the full path to the loaded Microsoft.Build.dll
/// </summary>
private static readonly Lazy<FileInfo> MSBuildAssemblyFullPathLazy = new Lazy<FileInfo>(() => new FileInfo(typeof(BuildManager).Assembly.Location));

/// <summary>
/// Executes a build for the specified project.
/// </summary>
Expand Down Expand Up @@ -84,74 +74,6 @@ public static BuildResult Build(ProjectInstance projectInstance, string[] target
return Build(buildRequestData, loggers);
}

/// <summary>
/// Sets the host for MSBuild to launch nodes. For .NET Core this is dotnet.exe and for .NET Framework this is MSBuild.exe.
/// This is a workaround for https://github.com/dotnet/msbuild/issues/6782
/// </summary>
/// <param name="buildManager">The current <see cref="BuildManager" />.</param>
public static void SetCurrentHost(BuildManager buildManager)
{
if (!IsDotNetCoreLazy.Value)
{
return;
}

string hostExePath = Path.Combine(Path.GetFullPath(Path.Combine(MSBuildAssemblyFullPathLazy.Value.DirectoryName!, "..", "..")), RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "dotnet.exe" : "dotnet");

if (!File.Exists(hostExePath))
{
return;
}

Type buildManagerType = buildManager.GetType();

FieldInfo? nodeManagerFieldInfo = buildManagerType.GetField("_nodeManager", BindingFlags.Instance | BindingFlags.NonPublic);

if (nodeManagerFieldInfo == null)
{
return;
}

object? nodeManager = nodeManagerFieldInfo.GetValue(buildManager);

if (nodeManager == null)
{
return;
}

Type nodeManagerType = nodeManager.GetType();

FieldInfo? outOfProcNodeProviderFieldInfo = nodeManagerType.GetField("_outOfProcNodeProvider", BindingFlags.Instance | BindingFlags.NonPublic);

if (outOfProcNodeProviderFieldInfo == null)
{
return;
}

object? outOfProcNodeProvider = outOfProcNodeProviderFieldInfo.GetValue(nodeManager);

if (outOfProcNodeProvider == null)
{
return;
}

Type? nodeProviderOutOfProcBaseType = outOfProcNodeProvider.GetType().BaseType;

if (nodeProviderOutOfProcBaseType == null)
{
return;
}

FieldInfo? currentHostFieldInfo = nodeProviderOutOfProcBaseType.GetField("CurrentHost", BindingFlags.Static | BindingFlags.NonPublic);

if (currentHostFieldInfo == null)
{
return;
}

currentHostFieldInfo.SetValue(outOfProcNodeProvider, hostExePath);
}

private static BuildResult Build(BuildRequestData buildRequestData, IEnumerable<ILogger> loggers)
{
lock (LockObject)
Expand All @@ -170,8 +92,6 @@ private static BuildResult Build(BuildRequestData buildRequestData, IEnumerable<
{
BuildSubmission buildSubmission = BuildManager.DefaultBuildManager.PendBuildRequest(buildRequestData);

SetCurrentHost(BuildManager.DefaultBuildManager);

BuildResult buildResult = buildSubmission.Execute();

if (buildResult.Exception != null)
Expand Down
8 changes: 8 additions & 0 deletions src/Microsoft.Build.Utilities.ProjectCreation/BuildOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public sealed class BuildOutput : BuildEventArgsCollection, ILogger
/// </summary>
private BuildFinishedEventArgs? _buildFinished;

private IEventSource? _eventSource;

private BuildOutput()
{
Parameters = string.Empty;
Expand Down Expand Up @@ -70,6 +72,8 @@ public override void Dispose()
/// <inheritdoc cref="ILogger.Initialize" />
public void Initialize(IEventSource eventSource)
{
_eventSource = eventSource;

eventSource.BuildFinished += OnBuildFinished;
eventSource.ProjectFinished += OnProjectFinished;
eventSource.AnyEventRaised += OnAnyEventRaised;
Expand All @@ -78,6 +82,10 @@ public void Initialize(IEventSource eventSource)
/// <inheritdoc cref="ILogger.Shutdown" />
public void Shutdown()
{
_eventSource?.BuildFinished -= OnBuildFinished;
_eventSource?.ProjectFinished -= OnProjectFinished;
_eventSource?.AnyEventRaised -= OnAnyEventRaised;

IsShutdown = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.Build.Utilities.ProjectCreation
/// Provides a base class for unit test classes that use MSBuild. This class resolves MSBuild related assemblies automatically.
/// </summary>
/// <remarks>
/// Prefer calling <see cref="MSBuildAssemblyResolver.Register"/> from a <c>ModuleInitalizerAttribute</c> if your target framework
/// Prefer calling <see cref="MSBuildAssemblyResolver.Register"/> from a <c>ModuleInitializerAttribute</c> if your target framework
/// supports one. This base class is provided for backwards compatibility with older versions of .NET.
/// </remarks>
public abstract class MSBuildTestBase
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;net9.0;net10.0</TargetFrameworks>
<TargetFrameworks>net472;net8.0;net10.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<ArtifactsPath>..\..\artifacts\$(MSBuildProjectName)</ArtifactsPath>
Expand Down
2 changes: 0 additions & 2 deletions src/Microsoft.Build.Utilities.ProjectCreation/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,6 @@ internal void WriteNuspec(Stream stream)
writer.WriteElementStringIfNotNull("iconUrl", IconUrl);
writer.WriteElementStringIfNotNull("developmentDependency", DevelopmentDependency);
writer.WriteElementStringIfNotNull("language", Language);
writer.WriteElementStringIfNotNull("title", Title);
writer.WriteElementStringIfNotNull("tags", Tags);
writer.WriteElementStringIfNotNull("summary", Summary);
writer.WriteElementStringIfNotNull("owners", Owners);
writer.WriteElementStringIfNotNull("releaseNotes", ReleaseNotes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,12 @@ private void CreateBuildFile(string extension, string folderName, Action<Project

if (string.IsNullOrWhiteSpace(extension))
{
throw new ArgumentNullException(extension);
throw new ArgumentNullException(nameof(extension));
}

if (string.IsNullOrWhiteSpace(folderName))
{
throw new ArgumentNullException(folderName);
throw new ArgumentNullException(nameof(folderName));
}

project = ProjectCreator.Create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public string GetInstallPath(string packageId, string version)
}

/// <summary>
/// Gets the full path to the specified package' <c>.nupsec</c> in the current <see cref="PackageRepository" />.
/// Gets the full path to the specified package' <c>.nuspec</c> in the current <see cref="PackageRepository" />.
/// </summary>
/// <param name="packageId">The ID of the package.</param>
/// <param name="version">The version of the package.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ private PackageRepository(string rootPath, IEnumerable<Uri>? feeds = null)
{
GlobalPackagesFolder = Path.Combine(rootPath, ".nuget", "packages");

_nugetPackagesGlobalFolderBackup = Environment.GetEnvironmentVariable("NUGET_PACKAGES");

Environment.SetEnvironmentVariable("NUGET_PACKAGES", null);

NuGetConfigPath = Path.Combine(rootPath, "NuGet.config");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public ProjectCreator TryBuild(out bool result)
/// <param name="globalProperties">Global properties to use when building the target.</param>
/// <param name="result">A value indicating the result of the build.</param>
/// <returns>The current <see cref="ProjectCreator" />.</returns>
public ProjectCreator TryBuild(Dictionary<string, string>? globalProperties, out bool result)
public ProjectCreator TryBuild(IDictionary<string, string>? globalProperties, out bool result)
{
return TryBuild(restore: false, globalProperties: globalProperties, out result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public ProjectCreator ItemCompile(string include, string? exclude = null, string
return ItemInclude(
itemType: "Compile",
include: include,
exclude: exclude,
metadata: metadata.Merge(new Dictionary<string, string?>
{
{ "DependentUpon", dependentUpon! },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ProjectCreator SdkCsproj(
public ProjectCreator SdkCsproj(
IEnumerable<string>? targetFrameworks,
string? path = null,
string sdk = "Microsoft.NET.Sdk",
string sdk = ProjectCreatorConstants.SdkCsprojDefaultSdk,
string? outputType = null,
Action<ProjectCreator>? projectCreator = null,
string? defaultTargets = null,
Expand Down
Loading
Loading