Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 7838a0a

Browse files
committed
Building packages fails under 15.3 preview
Fixes NuGet/Home#5356 Rolls back usage of Fody+Costura which isn't doing what we need it to do, and use ILRepack instead, which reliable isolate us from version mismatches. Fixed the issues we had before with running tests in the IDE properly so we can merge the IL on both debug and release builds.
1 parent 316b772 commit 7838a0a

8 files changed

Lines changed: 87 additions & 25 deletions

File tree

src/Build/NuGet.Build.Packaging.Tasks/FodyWeavers.xml

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/Build/NuGet.Build.Packaging.Tasks/NuGet.Build.Packaging.Tasks.csproj

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@
55
<PropertyGroup>
66
<ProjectGuid>{A3D231D7-31E4-4A70-8CD1-7246C7D069F6}</ProjectGuid>
77
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
8-
<OutputType>Exe</OutputType>
9-
<TargetExt>.dll</TargetExt>
10-
<StartupObject>NuGet.Build.Packaging.Program</StartupObject>
118
</PropertyGroup>
129
<ItemGroup>
1310
<Reference Include="System" />
1411
<Reference Include="System.Core" />
1512
</ItemGroup>
1613
<ItemGroup>
17-
<PackageReference Include="Costura.Fody" Version="1.3.3" PrivateAssets="all" />
18-
<PackageReference Include="Fody" Version="1.29.4" PrivateAssets="all" />
1914
<PackageReference Include="GitInfo" Version="1.1.61" PrivateAssets="all" />
15+
<PackageReference Include="ILRepack" Version="2.0.13" PrivateAssets="all" />
2016
<PackageReference Include="netfx-System.StringResources" Version="3.0.14" PrivateAssets="all" />
2117
<PackageReference Include="Microsoft.Build" Version="14.3.0" PrivateAssets="all" />
2218
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="14.3.0" PrivateAssets="all" />
@@ -27,7 +23,6 @@
2723
<PackageReference Include="NuGet.ProjectManagement" Version="4.0.0" PrivateAssets="all" />
2824
</ItemGroup>
2925
<ItemGroup>
30-
<Content Include="FodyWeavers.xml" />
3126
<Content Include="NuGet.Build.Packaging.props" />
3227
<Content Include="NuGet.Build.Packaging.targets" />
3328
<Content Include="NuGet.Build.Packaging.CrossTargeting.targets" />

src/Build/NuGet.Build.Packaging.Tasks/NuGet.Build.Packaging.Tasks.targets

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,36 @@ namespace $(RootNamespace)
105105
</ItemGroup>
106106
</Target>
107107

108+
<Target Name="ILRepack"
109+
AfterTargets="CoreCompile"
110+
DependsOnTargets="CoreCompile"
111+
Returns="@(MergedAssemblies)"
112+
Condition="'$(ILRepack)' != 'false'">
113+
<GetReferenceAssemblyPaths BypassFrameworkInstallChecks="False" TargetFrameworkMoniker="$(TargetFrameworkMoniker)">
114+
<Output TaskParameter="FullFrameworkReferenceAssemblyPaths" PropertyName="FullFrameworkReferenceAssemblyPaths" />
115+
</GetReferenceAssemblyPaths>
116+
<ItemGroup>
117+
<MergedAssemblies Include="@(ReferenceCopyLocalPaths)" Condition="$([System.String]::new('%(FileName)').StartsWith('Newtonsoft'))" />
118+
<MergedAssemblies Include="@(ReferenceCopyLocalPaths)" Condition="$([System.String]::new('%(FileName)').StartsWith('NuGet'))" />
119+
<ReferenceCopyLocalDirs Include="@(ReferenceCopyLocalPaths -> '%(RootDir)%(Directory)')" />
120+
<ReferenceCopyLocalPaths Remove="@(MergedAssemblies)" />
121+
<LibDir Include="@(ReferenceCopyLocalDirs->Distinct())" />
122+
</ItemGroup>
123+
<PropertyGroup>
124+
<ILRepackArgs Condition="'$(AssemblyOriginatorKeyFile)' != ''">/keyfile:&quot;$(AssemblyOriginatorKeyFile)&quot;</ILRepackArgs>
125+
</PropertyGroup>
126+
<Exec Command="&quot;$(ILRepack)&quot; @(LibDir->'/lib:&quot;%(Identity).&quot;', ' ') $(ILRepackArgs) /targetplatform:&quot;v4,$(FullFrameworkReferenceAssemblyPaths.TrimEnd(\\))&quot; /out:&quot;@(IntermediateAssembly->'%(FullPath)')&quot; &quot;@(IntermediateAssembly->'%(FullPath)')&quot; @(MergedAssemblies->'&quot;%(FullPath)&quot;', ' ')"
127+
WorkingDirectory="$(MSBuildProjectDirectory)\$(OutputPath)"
128+
StandardErrorImportance="high"
129+
StandardOutputImportance="low"
130+
ConsoleToMSBuild="true"
131+
ContinueOnError="true">
132+
<Output TaskParameter="ConsoleOutput" PropertyName="ILRepackOutput"/>
133+
<Output TaskParameter="ExitCode" PropertyName="ExitCode"/>
134+
</Exec>
135+
<Message Importance="high" Text="$(ILRepackOutput)" Condition="'$(ExitCode)' != '0'" />
136+
<Error Text="$(ILRepackOutput)" Condition="'$(ExitCode)' != '0' And '$(ContinueOnError)' != 'true'" />
137+
<Delete Files="@(MergedAssemblies -> '$(MSBuildProjectDirectory)\$(OutputPath)%(Filename)%(Extension)')" Condition="Exists('$(MSBuildProjectDirectory)\$(OutputPath)%(Filename)%(Extension)')" />
138+
</Target>
139+
108140
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<configuration>
2+
<runtime>
3+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
4+
<!-- MSBuild 4 > 14 -->
5+
<dependentAssembly>
6+
<assemblyIdentity name="Microsoft.Build" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
7+
<bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="14.0.0.0" />
8+
</dependentAssembly>
9+
<dependentAssembly>
10+
<assemblyIdentity name="Microsoft.Build.Framework" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
11+
<bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="14.0.0.0" />
12+
</dependentAssembly>
13+
<dependentAssembly>
14+
<assemblyIdentity name="Microsoft.Build.Tasks.Core" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
15+
<bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="14.0.0.0" />
16+
</dependentAssembly>
17+
<dependentAssembly>
18+
<assemblyIdentity name="Microsoft.Build.Utilities.Core" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
19+
<bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="14.0.0.0" />
20+
</dependentAssembly>
21+
</assemblyBinding>
22+
</runtime>
23+
</configuration>

src/Build/NuGet.Build.Packaging.Tests/Builder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static BuildResult Build(ProjectInstance project, string targets, Diction
2929
//Environment.SetEnvironmentVariable("MSBUILDNOINPROCNODE", "1", EnvironmentVariableTarget.Process);
3030
using (var manager = new BuildManager(Guid.NewGuid().ToString()))
3131
{
32-
var request = new BuildRequestData(project, targets.Split(','), null);
32+
var request = new BuildRequestData(project, targets.Split(','));
3333
var parameters = new BuildParameters
3434
{
3535
GlobalProperties = properties,

src/Build/NuGet.Build.Packaging.Tests/NuGet.Build.Packaging.Tests.csproj

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,31 @@
1313
<Reference Include="System.Core" />
1414
<Reference Include="System.Xml" />
1515
<Reference Include="System.Xml.Linq" />
16+
<Reference Include="NuGet.Build.Packaging.Tasks">
17+
<HintPath>..\NuGet.Build.Packaging.Tasks\bin\$(Configuration)\NuGet.Build.Packaging.Tasks.dll</HintPath>
18+
</Reference>
1619
</ItemGroup>
1720
<ItemGroup>
1821
<PackageReference Include="GitInfo" Version="1.1.61" />
19-
<PackageReference Include="Microsoft.Build" Version="14.3.0" />
20-
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="14.3.0" />
21-
<PackageReference Include="Newtonsoft.Json" Version="6.0.8" />
22+
<PackageReference Include="Microsoft.Build" Version="14.3.0" PrivateAssets="all" />
23+
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="14.3.0" PrivateAssets="all" />
2224
<PackageReference Include="MSBuilder.Dump" Version="*" />
2325
<PackageReference Include="MSBuilder.DumpItems" Version="*" />
2426
<PackageReference Include="MSBuilder.Introspect" Version="*" />
27+
<PackageReference Include="System.IO.Compression">
28+
<Version>4.3.0</Version>
29+
</PackageReference>
30+
<PackageReference Include="System.IO.Compression.ZipFile">
31+
<Version>4.3.0</Version>
32+
</PackageReference>
2533
<PackageReference Include="xunit" Version="2.2.0" />
2634
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
27-
<PackageReference Include="NuGet.Client" Version="4.0.0" />
28-
<PackageReference Include="NuGet.Packaging" Version="4.0.0" />
29-
<PackageReference Include="NuGet.ProjectManagement" Version="4.0.0" />
3035
</ItemGroup>
3136
<ItemGroup>
37+
<Content Include="App.config">
38+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
39+
<SubType>Designer</SubType>
40+
</Content>
3241
<None Include="NuGet.Build.Packaging.Tests.targets" />
3342
<Content Include="Scenarios\given_a_custom_build_project\Readme.txt" />
3443
<Content Include="Scenarios\given_a_library_with_content\content-copy.txt" />
@@ -161,10 +170,6 @@
161170
<Project>{cd767d93-6c99-4d6a-a303-3c139a73400e}</Project>
162171
<Name>ApiIntersect</Name>
163172
</ProjectReference>
164-
<ProjectReference Include="..\NuGet.Build.Packaging.Tasks\NuGet.Build.Packaging.Tasks.csproj">
165-
<Project>{a3d231d7-31e4-4a70-8cd1-7246c7d069f6}</Project>
166-
<Name>NuGet.Build.Packaging.Tasks</Name>
167-
</ProjectReference>
168173
</ItemGroup>
169174
<ItemGroup>
170175
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />

src/Build/NuGet.Build.Packaging.Tests/NuGet.Build.Packaging.Tests.targets

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@
44
<PropertyGroup>
55
<!-- Prevents Fody.VerifyTask from running -->
66
<NCrunch>1</NCrunch>
7+
<!-- Don't reference the Tasks project, we are referring to its binary output instead -->
8+
<AddSyntheticProjectReferencesForSolutionDependencies>false</AddSyntheticProjectReferencesForSolutionDependencies>
79
</PropertyGroup>
8-
10+
911
<Target Name="AfterBuild">
1012
<ItemGroup>
1113
<ScenarioFile Include="Scenarios\**\*.*" Exclude="Scenarios\**\bin\**\*.*;Scenarios\**\obj\**\*.*" />
14+
<NuGetizer Include="..\NuGet.Build.Packaging.Tasks\bin\$(Configuration)\**\*.*" />
1215
</ItemGroup>
1316

1417
<Copy SourceFiles="@(ScenarioFile)"
15-
DestinationFiles="@(ScenarioFile -> '$(OutputPath)Scenarios\%(RecursiveDir)%(Filename)%(Extension)')"
16-
SkipUnchangedFiles="true" />
18+
DestinationFiles="@(ScenarioFile -> '$(OutputPath)Scenarios\%(RecursiveDir)%(Filename)%(Extension)')"
19+
SkipUnchangedFiles="true" />
20+
<Copy SourceFiles="@(NuGetizer)"
21+
DestinationFiles="@(NuGetizer -> '$(OutputPath)%(RecursiveDir)%(Filename)%(Extension)')"
22+
SkipUnchangedFiles="true" />
1723
</Target>
18-
24+
1925
</Project>

src/Build/NuGet.Build.Packaging.sln

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio 15
3-
VisualStudioVersion = 15.0.26510.0
3+
VisualStudioVersion = 15.0.26602.0
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGet.Build.Packaging.Tasks", "NuGet.Build.Packaging.Tasks\NuGet.Build.Packaging.Tasks.csproj", "{A3D231D7-31E4-4A70-8CD1-7246C7D069F6}"
66
EndProject
77
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BD16CBB5-BD47-4CC3-A9FD-7F1B9077455D}"
88
ProjectSection(SolutionItems) = preProject
9+
..\..\.editorconfig = ..\..\.editorconfig
910
..\..\appveyor.yml = ..\..\appveyor.yml
1011
Before.NuGet.Build.Packaging.sln.targets = Before.NuGet.Build.Packaging.sln.targets
1112
..\..\build.cmd = ..\..\build.cmd
@@ -21,6 +22,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2122
EndProjectSection
2223
EndProject
2324
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGet.Build.Packaging.Tests", "NuGet.Build.Packaging.Tests\NuGet.Build.Packaging.Tests.csproj", "{212952C3-22F5-4263-BF9B-B17316B3B3CA}"
25+
ProjectSection(ProjectDependencies) = postProject
26+
{A3D231D7-31E4-4A70-8CD1-7246C7D069F6} = {A3D231D7-31E4-4A70-8CD1-7246C7D069F6}
27+
EndProjectSection
2428
EndProject
2529
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiIntersect", "..\..\external\ApiIntersect\ApiIntersect\ApiIntersect.csproj", "{CD767D93-6C99-4D6A-A303-3C139A73400E}"
2630
EndProject

0 commit comments

Comments
 (0)