Skip to content

Commit 43fd928

Browse files
authored
Build in-proc, improve assembly loading (#142)
Out-of-proc builds were causing hangs and I added them to get around assembly loading issues. This change gets rid of any API that returns NuGet and improves how assemblies are loaded in .NET 6. Fixes #134
1 parent 14d2b11 commit 43fd928

File tree

71 files changed

+2097
-1050
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2097
-1050
lines changed

.github/workflows/CI.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ jobs:
5353
- name: Build Solution
5454
run: dotnet build "/p:Platform=${{ env.BuildPlatform }}" "/p:Configuration=${{ env.BuildConfiguration }}" "/BinaryLogger:${{ env.ArtifactsDirectoryName }}\msbuild.binlog"
5555

56+
- name: Run Unit Tests (.NET Framework)
57+
run: dotnet test --logger trx --no-restore --no-build --framework net472 /noautorsp
58+
5659
- name: Run Unit Tests (.NET Core 3.1)
57-
run: dotnet test --logger trx --no-restore --no-build --framework netcoreapp3.1 /restore:false
60+
run: dotnet test --logger trx --no-restore --no-build --framework netcoreapp3.1 /noautorsp
5861

5962
- name: Run Unit Tests (.NET 5)
60-
run: dotnet test --logger trx --no-restore --no-build --framework net5.0 /restore:false
63+
run: dotnet test --logger trx --no-restore --no-build --framework net5.0 /noautorsp
6164

6265
- name: Run Unit Tests (.NET 6)
63-
run: dotnet test --logger trx --no-restore --no-build --framework net6.0 /restore:false
64-
65-
- name: Run Unit Tests (.NET Framework)
66-
run: dotnet test --logger trx --no-restore --no-build --framework net472 /restore:false
66+
run: dotnet test --logger trx --no-restore --no-build --framework net6.0 /noautorsp
6767

6868
- name: Upload Test Results
6969
uses: actions/upload-artifact@v2
@@ -114,13 +114,13 @@ jobs:
114114
run: dotnet build "/p:Platform=${{ env.BuildPlatform }}" "/p:Configuration=${{ env.BuildConfiguration }}" "/BinaryLogger:${{ env.ArtifactsDirectoryName }}\msbuild.binlog"
115115

116116
- name: Run Unit Tests (.NET Core 3.1)
117-
run: dotnet test --logger trx --no-restore --no-build --framework netcoreapp3.1 /restore:false
117+
run: dotnet test --logger trx --no-restore --no-build --framework netcoreapp3.1 /noautorsp
118118

119119
- name: Run Unit Tests (.NET 5)
120-
run: dotnet test --logger trx --no-restore --no-build --framework net5.0 /restore:false
120+
run: dotnet test --logger trx --no-restore --no-build --framework net5.0 /noautorsp
121121

122122
- name: Run Unit Tests (.NET 6)
123-
run: dotnet test --logger trx --no-restore --no-build --framework net6.0 /restore:false
123+
run: dotnet test --logger trx --no-restore --no-build --framework net6.0 /noautorsp
124124

125125
- name: Upload Test Results
126126
uses: actions/upload-artifact@v2
@@ -167,13 +167,13 @@ jobs:
167167
run: dotnet build "/p:Platform=${{ env.BuildPlatform }}" "/p:Configuration=${{ env.BuildConfiguration }}" "/BinaryLogger:${{ env.ArtifactsDirectoryName }}\msbuild.binlog"
168168

169169
- name: Run Unit Tests (.NET Core 3.1)
170-
run: dotnet test --logger trx --no-restore --no-build --framework netcoreapp3.1 /restore:false
170+
run: dotnet test --logger trx --no-restore --no-build --framework netcoreapp3.1 /noautorsp
171171

172172
- name: Run Unit Tests (.NET 5)
173-
run: dotnet test --logger trx --no-restore --no-build --framework net5.0 /restore:false
173+
run: dotnet test --logger trx --no-restore --no-build --framework net5.0 /noautorsp
174174

175175
- name: Run Unit Tests (.NET 6)
176-
run: dotnet test --logger trx --no-restore --no-build --framework net6.0 /restore:false
176+
run: dotnet test --logger trx --no-restore --no-build --framework net6.0 /noautorsp
177177

178178
- name: Upload Test Results
179179
uses: actions/upload-artifact@v2

MSBuildProjectCreator.sln

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{8339FD67
1111
ProjectSection(SolutionItems) = preProject
1212
.gitattributes = .gitattributes
1313
.gitignore = .gitignore
14-
azure-pipelines.yml = azure-pipelines.yml
1514
CONTRIBUTING.md = CONTRIBUTING.md
1615
Directory.Build.props = Directory.Build.props
1716
Directory.Build.rsp = Directory.Build.rsp

Packages.props

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
<MicrosoftBuildPackageVersion>16.11.0</MicrosoftBuildPackageVersion>
55
<MicrosoftBuildPackageVersion Condition="'$(TargetFramework)' == 'netcoreapp3.1'">16.9.0</MicrosoftBuildPackageVersion>
66
<NuGetPackageVersion>5.11.0</NuGetPackageVersion>
7-
<NuGetPackageVersion Condition="'$(TargetFramework)' == 'netcoreapp3.1'">5.7.1</NuGetPackageVersion>
7+
<NuGetPackageVersion Condition="'$(TargetFramework)' == 'net6.0'">6.0.0</NuGetPackageVersion>
88
</PropertyGroup>
99
<ItemGroup>
1010
<PackageReference Update="Microsoft.Build" Version="$(MicrosoftBuildPackageVersion)" />
1111
<PackageReference Update="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildPackageVersion)" />
1212
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="3.11.0" />
13+
<PackageReference Update="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.3" />
1314
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.0.0" />
1415
<PackageReference Update="Microsoft.VisualStudio.SDK.EmbedInteropTypes" Version="15.0.36" />
1516
<PackageReference Update="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="1.16.30" />
@@ -24,7 +25,7 @@
2425
<GlobalPackageReference Include="Microsoft.Build.Artifacts" Version="2.2.0" />
2526
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" />
2627
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.4.244" Condition=" '$(EnableGitVersioning)' != 'false' " />
27-
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.1.118" Condition=" '$(EnableStyleCopAnalyzers)' != 'false' " />
28+
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.354" Condition=" '$(EnableStyleCopAnalyzers)' != 'false' " />
2829
</ItemGroup>
2930

3031
<ItemGroup Condition=" '$(EnableStyleCopAnalyzers)' != 'false' ">

src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/Microsoft.Build.Utilities.ProjectCreation.UnitTests.csproj

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net472;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
3+
<TargetFrameworks Condition="'$(MSBuildAssemblyVersion)' &gt;= '17.0'">net472;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
4+
<TargetFrameworks Condition="'$(TargetFrameworks)' == ''">net472;netcoreapp3.1;net5.0</TargetFrameworks>
45
<IsPackable>false</IsPackable>
56
</PropertyGroup>
67
<Import Project="..\Microsoft.Build.Utilities.ProjectCreation\build\MSBuild.ProjectCreation.props" Condition="'$(TargetFramework)' == 'net472'" />
8+
<ItemGroup>
9+
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
10+
</ItemGroup>
711
<ItemGroup>
812
<PackageReference Include="Microsoft.NET.Test.Sdk" />
13+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
14+
<PackageReference Include="NuGet.Frameworks" />
15+
<PackageReference Include="NuGet.Packaging" />
916
<PackageReference Include="Shouldly" />
1017
<PackageReference Include="xunit" />
1118
<PackageReference Include="xunit.runner.visualstudio" />
19+
<PackageReference Update="NuGet.*" ExcludeAssets="Runtime" Condition="'$(TargetFramework)' == 'net472'" />
20+
</ItemGroup>
21+
<ItemGroup>
22+
<Reference Include="System.IO.Compression" Condition="'$(TargetFramework)' == 'net472'" />
1223
</ItemGroup>
1324
<ItemGroup>
1425
<ProjectReference Include="..\Microsoft.Build.Utilities.ProjectCreation\Microsoft.Build.Utilities.ProjectCreation.csproj" />

src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedFileTests.cs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using NuGet.Frameworks;
66
using NuGet.Packaging;
77
using NuGet.Packaging.Core;
8-
using NuGet.ProjectModel;
98
using Shouldly;
109
using System;
1110
using System.IO;
@@ -23,17 +22,15 @@ public void ContentFileTextCustom()
2322

2423
PackageFeed.Create(FeedRootPath)
2524
.Package("PackageA", "1.0.0", out Package packageA)
26-
.ContentFileText("file.cs", "A1CF42B9F20B4155B6B70753784615B5", FrameworkConstants.CommonFrameworks.NetStandard20, BuildAction.Compile, copyToOutput: false, flatten: true, language)
25+
.ContentFileText("file.cs", "A1CF42B9F20B4155B6B70753784615B5", "netstandard2.0", "Compile", copyToOutput: false, flatten: true, language)
2726
.Save();
2827

29-
using PackageArchiveReader packageArchiveReader = GetPackageArchiveReader(packageA);
30-
3128
VerifyContentFile(
32-
packageArchiveReader,
29+
packageA,
3330
"file.cs",
3431
"A1CF42B9F20B4155B6B70753784615B5",
3532
FrameworkConstants.CommonFrameworks.NetStandard20,
36-
expectedBuildAction: BuildAction.Compile.Value,
33+
expectedBuildAction: "Compile",
3734
expectedCopyToOutput: false,
3835
expectedFlatten: true,
3936
expectedLanguage: language);
@@ -44,17 +41,15 @@ public void ContentFileTextDefault()
4441
{
4542
PackageFeed.Create(FeedRootPath)
4643
.Package("PackageA", "1.0.0", out Package packageA)
47-
.ContentFileText("file.txt", "F1BE6E0E408141459C9728FBE0CD5751", FrameworkConstants.CommonFrameworks.Net45)
44+
.ContentFileText("file.txt", "F1BE6E0E408141459C9728FBE0CD5751", "net45")
4845
.Save();
4946

50-
using PackageArchiveReader packageArchiveReader = GetPackageArchiveReader(packageA);
51-
5247
VerifyContentFile(
53-
packageArchiveReader,
48+
packageA,
5449
"file.txt",
5550
"F1BE6E0E408141459C9728FBE0CD5751",
5651
FrameworkConstants.CommonFrameworks.Net45,
57-
expectedBuildAction: BuildAction.Content.Value,
52+
expectedBuildAction: "Content",
5853
expectedCopyToOutput: true);
5954
}
6055

@@ -72,11 +67,12 @@ public void FileCustom()
7267
.FileCustom(Path.Combine("tools", "net46", fileName), fileInfo)
7368
.Save();
7469

75-
using PackageArchiveReader packageArchiveReader = GetPackageArchiveReader(packageA);
76-
77-
GetFileContents(packageArchiveReader, $"tools/net46/{fileName}").ShouldBe("585B55DD5AC54A10B841B3D9A00129D8");
70+
GetFileContents(packageA.FullPath, $"tools/net46/{fileName}")
71+
.ShouldBe("585B55DD5AC54A10B841B3D9A00129D8");
7872

79-
packageArchiveReader.NuspecReader.GetDependencyGroups().Select(i => i.TargetFramework).ToList().ShouldContain(FrameworkConstants.CommonFrameworks.Net46);
73+
GetNuspecReader(packageA)
74+
.GetDependencyGroups().Select(i => i.TargetFramework.GetShortFolderName()).ToList()
75+
.ShouldContain("net46");
8076
}
8177

8278
[Fact]
@@ -101,11 +97,12 @@ public void FileText()
10197
.FileText(@"something\nothing.txt", "607779BADE3645F8A288543213BFE948")
10298
.Save();
10399

104-
using PackageArchiveReader packageArchiveReader = GetPackageArchiveReader(packageA);
100+
GetFileContents(packageA.FullPath, "something/nothing.txt")
101+
.ShouldBe("607779BADE3645F8A288543213BFE948");
105102

106-
GetFileContents(packageArchiveReader, "something/nothing.txt").ShouldBe("607779BADE3645F8A288543213BFE948");
107-
108-
packageArchiveReader.NuspecReader.GetDependencyGroups().ShouldBeEmpty();
103+
GetNuspecReader(packageA)
104+
.GetDependencyGroups()
105+
.ShouldBeEmpty();
109106
}
110107

111108
[Fact]
@@ -118,13 +115,15 @@ public void FileTextThrowsIfNoPackageAdded()
118115
});
119116
}
120117

121-
private void VerifyContentFile(PackageArchiveReader packageArchiveReader, string relativePath, string expectedContents, NuGetFramework expectedTargetFramework, string expectedExclude = null, string expectedBuildAction = null, bool expectedCopyToOutput = false, bool expectedFlatten = false, string expectedLanguage = "any")
118+
private void VerifyContentFile(Package package, string relativePath, string expectedContents, NuGetFramework expectedTargetFramework, string expectedExclude = null, string expectedBuildAction = null, bool expectedCopyToOutput = false, bool expectedFlatten = false, string expectedLanguage = "any")
122119
{
123-
GetFileContents(packageArchiveReader, $"contentFiles/{expectedLanguage}/{expectedTargetFramework.GetShortFolderName()}/{relativePath}").ShouldBe(expectedContents);
120+
GetFileContents(package.FullPath, $"contentFiles/{expectedLanguage}/{expectedTargetFramework.GetShortFolderName()}/{relativePath}").ShouldBe(expectedContents);
121+
122+
NuspecReader nuspecReader = GetNuspecReader(package);
124123

125-
ContentFilesEntry file = packageArchiveReader.NuspecReader.GetContentFiles().ShouldHaveSingleItem();
124+
ContentFilesEntry file = nuspecReader.GetContentFiles().ShouldHaveSingleItem();
126125

127-
file.BuildAction.ShouldBe(expectedBuildAction);
126+
file.BuildAction.ShouldBe(expectedBuildAction, StringCompareShould.IgnoreCase);
128127

129128
if (expectedCopyToOutput)
130129
{

src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedLibraryTests.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void LibraryDefault(string packageName)
3030
{
3131
PackageFeed.Create(FeedRootPath)
3232
.Package(packageName, "1.0.0", out Package packageA)
33-
.Library(FrameworkConstants.CommonFrameworks.Net45)
33+
.Library(FrameworkConstants.CommonFrameworks.Net45.GetShortFolderName())
3434
.Save();
3535

3636
ValidateAssembly(packageA, $@"lib/net45/{packageName}.dll", $"{packageName}, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", $"{packageName}.{packageName.Replace(".", "_")}_Class");
@@ -42,17 +42,17 @@ public void LibraryThrowsIfNoPackageAdded()
4242
ShouldThrowExceptionIfNoPackageAdded(() =>
4343
{
4444
PackageFeed.Create(FeedRootPath)
45-
.Library(FrameworkConstants.CommonFrameworks.Net45);
45+
.Library(FrameworkConstants.CommonFrameworks.Net45.GetShortFolderName());
4646
});
4747
}
4848

4949
[Fact]
5050
public void MultipleTargetFrameworks()
5151
{
52-
NuGetFramework[] targetFrameworks =
52+
string[] targetFrameworks =
5353
{
54-
FrameworkConstants.CommonFrameworks.Net45,
55-
FrameworkConstants.CommonFrameworks.Net46,
54+
FrameworkConstants.CommonFrameworks.Net45.GetShortFolderName(),
55+
FrameworkConstants.CommonFrameworks.Net46.GetShortFolderName(),
5656
};
5757

5858
PackageFeed.Create(FeedRootPath)
@@ -66,10 +66,10 @@ public void MultipleTargetFrameworks()
6666
})
6767
.Save();
6868

69-
foreach (NuGetFramework targetFramework in targetFrameworks)
69+
foreach (string targetFramework in targetFrameworks)
7070
{
71-
ValidateAssembly(packageA, $@"lib/{targetFramework.GetShortFolderName()}/PackageA.dll", "PackageA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "PackageA.PackageA_Class");
72-
ValidateAssembly(packageA, $@"ref/{targetFramework.GetShortFolderName()}/PackageA.dll", "PackageA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "PackageA.PackageA_Class");
71+
ValidateAssembly(packageA, $@"lib/{targetFramework}/PackageA.dll", "PackageA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "PackageA.PackageA_Class");
72+
ValidateAssembly(packageA, $@"ref/{targetFramework}/PackageA.dll", "PackageA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "PackageA.PackageA_Class");
7373
}
7474
}
7575

@@ -89,7 +89,7 @@ public void ReferenceAssemblyDefault()
8989
{
9090
PackageFeed.Create(FeedRootPath)
9191
.Package("PackageA", "1.0.0", out Package packageA)
92-
.ReferenceAssembly(FrameworkConstants.CommonFrameworks.Net45)
92+
.ReferenceAssembly(FrameworkConstants.CommonFrameworks.Net45.GetShortFolderName())
9393
.Save();
9494

9595
ValidateAssembly(packageA, @"ref/net45/PackageA.dll", "PackageA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "PackageA.PackageA_Class");
@@ -101,15 +101,13 @@ public void ReferenceAssemblyThrowsIfNoPackageAdded()
101101
ShouldThrowExceptionIfNoPackageAdded(() =>
102102
{
103103
PackageFeed.Create(FeedRootPath)
104-
.ReferenceAssembly(FrameworkConstants.CommonFrameworks.Net45);
104+
.ReferenceAssembly(FrameworkConstants.CommonFrameworks.Net45.GetShortFolderName());
105105
});
106106
}
107107

108108
private void ValidateAssembly(Package package, string filePath, string expectedAssemblyFullName, string expectedTypeFullName)
109109
{
110-
PackageArchiveReader packageArchiveReader = GetPackageArchiveReader(package);
111-
112-
Assembly assembly = LoadAssembly(packageArchiveReader, filePath);
110+
Assembly assembly = LoadAssembly(package.FullPath, filePath);
113111

114112
assembly.FullName.ShouldBe(expectedAssemblyFullName);
115113

src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedTemplatesTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public void SinglePackageTemplate()
1515
PackageFeed.Templates.SinglePackage(FeedRootPath, out Package package);
1616

1717
package.Id.ShouldBe("SomePackage");
18-
package.Version.OriginalVersion.ShouldBe("1.0.0");
18+
package.Version.ShouldBe("1.0.0");
1919
}
2020
}
2121
}

0 commit comments

Comments
 (0)