Skip to content

Commit dc49cf9

Browse files
pjcollinsjonpryor
authored andcommitted
[build] Sanitize Microsoft.Build* assembly references (#3995)
Context: https://github.com/xamarin/monodroid/pull/1048 Context: #3928 Attempt to clean up and modernize various projects to help break up the scope of change required to convert them to .NET Standard libs. Bump the .NET Core version that `build.groovy` and `azure-pipelines.yaml` install to 3.1.100. This is to obtain various NuGet support fixes. Updates the shared `MSBuildReferences.projitems` file to instead include NuGet `@(PackageReference)`s to the required `Microsoft.Build.*.dll` assemblies. The `Mono.Posix.NETStandard`, `Xamarin.Build.AsyncTask`, and `Xamarin.LibZipSharp` NuGet references have also been moved into this file to make it easier to update versions in one place as needed. We're only using the compile time assets from the MSBuild NuGet packages, which ensures that their content is not copied to the output directory. An additional `@(None)` item group has been added to this file to copy the required assemblies from the system to the output directory so that `Xamarin.Android.Build.Tests.dll` can run against them. These changes are required because the MSBuild assemblies coming from NuGet do not yet fully support running on Mono. All projects which reference `MSBuildReferences.projitems` have been converted from the old `packages.config` to the new `@(PackageReference)` NuGet reference style. The Azure Pipeline build job has been updated to completely build `Xamarin.Android-Tests.sln` with `xabuild`, rather than only building select projects. This was done to mirror our Jenkins build and to ensure that `make all-tests` continues to work moving forward. .NET Core and `NuGetCommand` tasks have been bumped to bring in a newer version of NuGet with better `@(PackageReference)` support. NuGet restore will be skipped if any issues occur when calculating the dependency graph for the solution or project that it is operating on. A lot of our sources attempt to import `.props`/`.targets`/`.projitems` files that are generated by the build, and these should be conditionally imported so that NuGet restore attempts can succeed before these files are generated. This should also help when loading these projects in VS or VS Mac. Example NuGet restore error: src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.targets(8,3): error MSB4019: The imported project "bin/BuildRelease/ProfileAssemblies.projitems" was not found. Confirm that the expression in the Import declaration "../../bin/BuildRelease/ProfileAssemblies.projitems" is correct, and that the file exists on disk. /var/folders/pp/x88nqyvd0h18ttl996vv2c3w0000gn/T/NuGetScratch/ok90j1ok.3t3.nugetrestore.targets(266,5): warning : Skipping restore for project 'src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj'. The project file may be invalid or missing targets required for restore. I've also moved the `NuGet.exe` that is copied and used by tests into its own folder to avoid a crash on macOS which would occur when `NuGet.exe` is invoked from the same folder as `Xunit.NetCore.Extensions.dll`: mono bin/TestRelease/NuGet.exe VTable setup of type Xunit.NetCore.Extensions.SkippedTestCase failed System.TypeLoadException: VTable setup of type Xunit.NetCore.Extensions.SkippedTestCase failed at (wrapper managed-to-native) System.RuntimeType.GetPropertiesByName_native(System.RuntimeType,intptr,System.Reflection.BindingFlags,System.RuntimeType/MemberListType) at System.RuntimeType.GetPropertiesByName (System.String name, System.Reflection.BindingFlags bindingAttr, System.RuntimeType+MemberListType listType, System.RuntimeType reflectedType) at System.RuntimeType.GetPropertyCandidates (System.String name, System.Reflection.BindingFlags bindingAttr, System.Type[] types, System.Boolean allowPrefixLookup) at System.RuntimeType.GetProperties (System.Reflection.BindingFlags bindingAttr) at System.ComponentModel.Composition.AttributedModel.AttributedPartCreationInfo+<GetExportMembers>d__32.MoveNext () at System.Linq.Enumerable.Any[TSource] (System.Collections.Generic.IEnumerable1[T] source) ...
1 parent 7e7f0ba commit dc49cf9

File tree

35 files changed

+97
-315
lines changed

35 files changed

+97
-315
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ _PREPARE_ARGS =
2626

2727
BOOTSTRAP_SOLUTION = Xamarin.Android.BootstrapTasks.sln
2828
BOOTSTRAP_BUILD_LOG = bin/Build$(CONFIGURATION)/bootstrap-build.binlog
29-
BOOTSTRAP_MSBUILD_FLAGS = /binaryLogger:"$(BOOTSTRAP_BUILD_LOG)" $(PREPARE_COMMON_MSBUILD_FLAGS)
29+
BOOTSTRAP_MSBUILD_FLAGS = /t:Restore,Build /binaryLogger:"$(BOOTSTRAP_BUILD_LOG)" $(PREPARE_COMMON_MSBUILD_FLAGS)
3030

3131
all:
3232
$(call MSBUILD_BINLOG,all,$(_SLN_BUILD)) $(MSBUILD_FLAGS) $(SOLUTION)

build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks.csproj

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@
3535
<Reference Include="System.Net.Http" />
3636
<Reference Include="System.Xml" />
3737
<Reference Include="System.Xml.Linq" />
38-
<Reference Include="Mono.Posix.NETStandard">
39-
<HintPath>..\..\packages\Mono.Posix.NETStandard.1.0.0\lib\net40\Mono.Posix.NETStandard.dll</HintPath>
40-
</Reference>
41-
<Reference Include="libZipSharp">
42-
<HintPath>..\..\packages\Xamarin.LibZipSharp.1.0.6\lib\net45\libZipSharp.dll</HintPath>
43-
</Reference>
4438
</ItemGroup>
4539
<ItemGroup>
4640
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -67,6 +61,10 @@
6761
<Compile Include="Xamarin.Android.Tools.BootstrapTasks\RunInstrumentationTests.cs" />
6862
<Compile Include="Xamarin.Android.Tools.BootstrapTasks\JdkInfo.cs" />
6963
</ItemGroup>
64+
<ItemGroup>
65+
<PackageReference Include="Microsoft.DotNet.ApiCompat" Version="5.0.0-beta.19606.1" IncludeAssets="none" />
66+
<PackageReference Include="Microsoft.DotNet.GenAPI" Version="5.0.0-beta.19606.1" />
67+
</ItemGroup>
7068
<ItemGroup>
7169
<ProjectReference Include="..\xa-prep-tasks\xa-prep-tasks.csproj">
7270
<Project>{7CE69551-BD73-4726-ACAA-AAF89C84BAF8}</Project>
@@ -77,10 +75,6 @@
7775
<Name>Xamarin.Android.Tools.AndroidSdk</Name>
7876
</ProjectReference>
7977
</ItemGroup>
80-
<ItemGroup>
81-
<None Include="packages.config" />
82-
</ItemGroup>
8378
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
8479
<Import Project="result-packaging.targets" />
85-
<Import Project="..\..\packages\Xamarin.LibZipSharp.1.0.6\build\Xamarin.LibZipSharp.targets" Condition="Exists('..\..\packages\Xamarin.LibZipSharp.1.0.6\build\Xamarin.LibZipSharp.targets')" />
8680
</Project>

build-tools/Xamarin.Android.Tools.BootstrapTasks/packages.config

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

build-tools/api-xml-adjuster/api-xml-adjuster.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22

3-
<Import Project="..\..\bin\Build$(Configuration)\Mono.Android.Apis.projitems" />
3+
<Import Project="..\..\bin\Build$(Configuration)\Mono.Android.Apis.projitems" Condition="Exists('..\..\bin\Build$(Configuration)\Mono.Android.Apis.projitems')" />
44

55
<PropertyGroup>
66
<_TopDir>$(MSBuildThisFileDirectory)..\..</_TopDir>

build-tools/automation/azure-pipelines.yaml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ variables:
2121
InstallerArtifactName: installers
2222
TestAssembliesArtifactName: test-assemblies
2323
NUnitConsoleVersion: 3.9.0
24-
DotNetCoreVersion: 2.1.701
24+
DotNetCoreVersion: 3.1.100
2525
HostedMacMojave: Hosted Mac Internal Mojave
2626
HostedMac: Hosted Mac Internal
2727
HostedWinVS2019: Hosted Windows 2019 with VS2019
@@ -83,23 +83,8 @@ stages:
8383
displayName: make jenkins
8484

8585
# Build and package test assemblies
86-
- task: MSBuild@1
87-
displayName: msbuild tests/CodeBehind/UnitTests/CodeBehindUnitTests.csproj
88-
inputs:
89-
solution: $(System.DefaultWorkingDirectory)/tests/CodeBehind/UnitTests/CodeBehindUnitTests.csproj
90-
configuration: $(XA.Build.Configuration)
91-
92-
- task: MSBuild@1
93-
displayName: msbuild tests/CodeGen-MkBundle/Xamarin.Android.MakeBundle-UnitTests/Xamarin.Android.MakeBundle-UnitTests.csproj
94-
inputs:
95-
solution: $(System.DefaultWorkingDirectory)/tests/CodeGen-MkBundle/Xamarin.Android.MakeBundle-UnitTests/Xamarin.Android.MakeBundle-UnitTests.csproj
96-
configuration: $(XA.Build.Configuration)
97-
98-
- task: MSBuild@1
99-
displayName: msbuild tests/EmbeddedDSOs/EmbeddedDSO-UnitTests/EmbeddedDSO-UnitTests.csproj
100-
inputs:
101-
solution: $(System.DefaultWorkingDirectory)/tests/EmbeddedDSOs/EmbeddedDSO-UnitTests/EmbeddedDSO-UnitTests.csproj
102-
configuration: $(XA.Build.Configuration)
86+
- script: make all-tests V=1 CONFIGURATION=$(XA.Build.Configuration)
87+
displayName: make all-tests
10388

10489
- script: |
10590
cp -r bin/$(XA.Build.Configuration)/bcl-tests bin/Test$(XA.Build.Configuration)/bcl-tests

build-tools/automation/build.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ timestamps {
174174
}
175175
}
176176
}
177+
// Install .NET Core and temporarily append it to PATH
178+
sh "curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -version 3.1.100"
177179
}
178180

179181
utils.stageWithTimeout('build', 6, 'HOURS', XADir, true) { // Typically takes less than one hour except a build on a new bot to populate local caches can take several hours

build-tools/automation/yaml-templates/setup-test-environment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ steps:
3333
version: $(DotNetCoreVersion)
3434

3535
# Restore solutions for Xamarin.Android.Tools.sln, Xamarin.Android.sln, and Xamarin.Android-Tests.sln
36+
- task: NuGetToolInstaller@0
37+
inputs:
38+
versionSpec: 5.x
39+
3640
- task: NuGetCommand@2
3741
displayName: nuget restore Xamarin.Android solutions
3842
inputs:

build-tools/installers/create-installers.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="..\scripts\XAVersionInfo.targets" />
44
<Import Project="..\scripts\LocalizationLanguages.projitems" />
5-
<Import Project="..\..\bin\Build$(Configuration)\ProfileAssemblies.projitems" />
6-
<Import Project="..\..\bin\Build$(Configuration)\Mono.Android.Apis.projitems" />
5+
<Import Project="..\..\bin\Build$(Configuration)\ProfileAssemblies.projitems" Condition="Exists('..\..\bin\Build$(Configuration)\ProfileAssemblies.projitems')" />
6+
<Import Project="..\..\bin\Build$(Configuration)\Mono.Android.Apis.projitems" Condition="Exists('..\..\bin\Build$(Configuration)\Mono.Android.Apis.projitems')" />
77
<UsingTask AssemblyFile="..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.ReplaceFileContents" />
88
<PropertyGroup>
99
<RootBuildDir>$(XamarinAndroidSourcePath)bin\$(Configuration)\</RootBuildDir>
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<!--Import this file in projects needing to reference Microsoft.Build.*.dll -->
3-
<PropertyGroup>
4-
<MSBuildReferencePath Condition=" !$(MSBuildToolsPath.Contains('xbuild')) ">$(MSBuildToolsPath)</MSBuildReferencePath>
5-
<MSBuildReferencePath Condition=" $(MSBuildToolsPath.Contains('xbuild')) ">$([System.IO.Path]::GetFullPath ('$(MSBuildToolsPath)\..\..\..\msbuild\15.0\bin'))</MSBuildReferencePath>
6-
</PropertyGroup>
73
<ItemGroup>
8-
<Reference Include="Microsoft.Build">
9-
<HintPath>$(MSBuildReferencePath)\Microsoft.Build.dll</HintPath>
10-
</Reference>
11-
<Reference Include="Microsoft.Build.Engine">
12-
<HintPath>$(MSBuildReferencePath)\Microsoft.Build.Engine.dll</HintPath>
13-
</Reference>
14-
<Reference Include="Microsoft.Build.Framework">
15-
<HintPath>$(MSBuildReferencePath)\Microsoft.Build.Framework.dll</HintPath>
16-
</Reference>
17-
<Reference Include="Microsoft.Build.Tasks.Core">
18-
<HintPath>$(MSBuildReferencePath)\Microsoft.Build.Tasks.Core.dll</HintPath>
19-
</Reference>
20-
<Reference Include="Microsoft.Build.Utilities.Core">
21-
<HintPath>$(MSBuildReferencePath)\Microsoft.Build.Utilities.Core.dll</HintPath>
22-
</Reference>
4+
<!-- Compile against Microsoft.Build* NuGet refs, but do not copy to OutputDir. -->
5+
<PackageReference Include="Microsoft.Build" Version="15.9.20" IncludeAssets="compile" />
6+
<PackageReference Include="Microsoft.Build.Framework" Version="15.9.20" IncludeAssets="compile" />
7+
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="15.9.20" IncludeAssets="compile" />
8+
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.9.20" IncludeAssets="compile"/>
9+
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0" />
10+
<PackageReference Include="Xamarin.Build.AsyncTask" Version="0.3.4" />
11+
<PackageReference Include="Xamarin.LibZipSharp" Version="1.0.6" />
2312
</ItemGroup>
24-
</Project>
13+
<ItemGroup>
14+
<!-- Copy system Microsoft.Build*.dll and dependencies for tests to run against. We can remove this
15+
and rely entirely on NuGet assets when mono/msbuild is merged into microsoft/msbuild. -->
16+
<None Include="$(MSBuildToolsPath)\Microsoft.Build*.dll" >
17+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
18+
</None>
19+
<None Include="$(MSBuildToolsPath)\System.*.dll" >
20+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
</Project>

build-tools/scripts/XAVersionInfo.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.GitCommitsInRange" />
77
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.GitCommitTime" />
88
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.GitCommitInfo" />
9-
<Import Project="..\..\bin\Build$(Configuration)\MonoGitHash.props" />
9+
<Import Project="..\..\bin\Build$(Configuration)\MonoGitHash.props" Condition="Exists('..\..\bin\Build$(Configuration)\MonoGitHash.props')" />
1010
<Target Name="_GetSubmodulesVersionInfo">
1111
<ItemGroup>
1212
<!-- If anything changes in this list, make sure to update:

0 commit comments

Comments
 (0)