Skip to content

Commit

Permalink
[build] Move MSBuild tests to use @(PackageReference) (dotnet#2351)
Browse files Browse the repository at this point in the history
In a effort to reduce our dependency on external resources we should
not be relying on `NuGet.exe` to restore packages.  We should instead
be using `msbuild /t:Restore`.

However, `msbuild /t:Restore` only works with `@(PackageReference)`.

Move most of our NuGet references in the MSBuild tests over to use
`@(PackageReference)`.

The `BuildTest.BuildWithResolveAssembliesFailure()` test will
continue using `packages.config` to ensure that we don't accidentally
break compatibility with legacy NuGet.
  • Loading branch information
dellis1972 authored and jonpryor committed Oct 30, 2018
1 parent 3dc914d commit d0e86e8
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void CheckEmbeddedSupportLibraryResources ()
{
var proj = new XamarinAndroidApplicationProject () {
IsRelease = true,
Packages = {
PackageReferences = {
KnownPackages.SupportMediaCompat_25_4_0_1,
KnownPackages.SupportFragment_25_4_0_1,
KnownPackages.SupportCoreUtils_25_4_0_1,
Expand Down Expand Up @@ -284,10 +284,10 @@ public void Check9PatchFilesAreProcessed ([Values(false, true)] bool explicitCru
proj.AndroidResources.Add (image1);
}
proj.References.Add (new BuildItem ("ProjectReference", "..\\Library1\\Library1.csproj"));
proj.Packages.Add (KnownPackages.AndroidSupportV4_21_0_3_0);
proj.Packages.Add (KnownPackages.SupportV7AppCompat_21_0_3_0);
proj.Packages.Add (KnownPackages.SupportV7MediaRouter_21_0_3_0);
proj.Packages.Add (KnownPackages.GooglePlayServices_22_0_0_2);
proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_21_0_3_0);
proj.PackageReferences.Add (KnownPackages.SupportV7AppCompat_21_0_3_0);
proj.PackageReferences.Add (KnownPackages.SupportV7MediaRouter_21_0_3_0);
proj.PackageReferences.Add (KnownPackages.GooglePlayServices_22_0_0_2);
proj.AndroidExplicitCrunch = explicitCrunch;
proj.SetProperty ("TargetFrameworkVersion", "v5.0");
using (var b = CreateApkBuilder (Path.Combine (projectPath, "Application1"), false, false)) {
Expand Down Expand Up @@ -425,9 +425,9 @@ protected override void OnClick()
}
}"
});
proj.Packages.Add (KnownPackages.AndroidSupportV4_22_1_1_1);
proj.Packages.Add (KnownPackages.SupportV7AppCompat_22_1_1_1);
proj.Packages.Add (KnownPackages.SupportV7Palette_22_1_1_1);
proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_22_1_1_1);
proj.PackageReferences.Add (KnownPackages.SupportV7AppCompat_22_1_1_1);
proj.PackageReferences.Add (KnownPackages.SupportV7Palette_22_1_1_1);
proj.SetProperty ("TargetFrameworkVersion", "v5.0");
proj.SetProperty (proj.DebugProperties, "JavaMaximumHeapSize", "1G");
proj.SetProperty (proj.ReleaseProperties, "JavaMaximumHeapSize", "1G");
Expand Down Expand Up @@ -617,8 +617,8 @@ public void TargetGenerateJavaDesignerForComponentIsSkipped ([Values(false, true
var proj = new XamarinAndroidApplicationProject () {
IsRelease = isRelease,
};
proj.Packages.Add (KnownPackages.AndroidSupportV4_21_0_3_0);
proj.Packages.Add (KnownPackages.SupportV7AppCompat_21_0_3_0);
proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_21_0_3_0);
proj.PackageReferences.Add (KnownPackages.SupportV7AppCompat_21_0_3_0);
proj.SetProperty ("TargetFrameworkVersion", "v5.0");
using (var b = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) {
b.Verbosity = LoggerVerbosity.Diagnostic;
Expand Down Expand Up @@ -983,7 +983,7 @@ public void CheckFilesAreRemoved () {
</resources>",
}
},
Packages = {
PackageReferences = {
new Package (KnownPackages.AndroidSupportV13_21_0_3_0, audoAddReferences:true),
new Package (KnownPackages.AndroidSupportV4_21_0_3_0, audoAddReferences:true),
new Package (KnownPackages.SupportV7AppCompat_21_0_3_0, audoAddReferences:true),
Expand Down Expand Up @@ -1147,7 +1147,7 @@ public void BuildAppWithManagedResourceParserAndLibraries ()
References = {
new BuildItem.ProjectReference (@"..\Lib1\Lib1.csproj", libProj.ProjectName, libProj.ProjectGuid),
},
Packages = {
PackageReferences = {
KnownPackages.SupportMediaCompat_25_4_0_1,
KnownPackages.SupportFragment_25_4_0_1,
KnownPackages.SupportCoreUtils_25_4_0_1,
Expand Down Expand Up @@ -1378,20 +1378,20 @@ public void CustomViewAddResourceId ([Values (false, true)] bool useAapt2)
var proj = new XamarinAndroidApplicationProject ();
proj.SetProperty ("AndroidUseAapt2", useAapt2.ToString ());
proj.LayoutMain = proj.LayoutMain.Replace ("</LinearLayout>", "<android.support.design.widget.BottomNavigationView android:id=\"@+id/navigation\" /></LinearLayout>");
proj.Packages.Add (KnownPackages.Android_Arch_Core_Common_26_1_0);
proj.Packages.Add (KnownPackages.Android_Arch_Lifecycle_Common_26_1_0);
proj.Packages.Add (KnownPackages.Android_Arch_Lifecycle_Runtime_26_1_0);
proj.Packages.Add (KnownPackages.AndroidSupportV4_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportCompat_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportCoreUI_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportCoreUtils_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportDesign_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportFragment_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportMediaCompat_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportV7AppCompat_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportV7CardView_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportV7MediaRouter_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportV7RecyclerView_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.Android_Arch_Core_Common_26_1_0);
proj.PackageReferences.Add (KnownPackages.Android_Arch_Lifecycle_Common_26_1_0);
proj.PackageReferences.Add (KnownPackages.Android_Arch_Lifecycle_Runtime_26_1_0);
proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportCompat_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportCoreUI_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportCoreUtils_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportDesign_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportFragment_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportMediaCompat_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportV7AppCompat_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportV7CardView_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportV7MediaRouter_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportV7RecyclerView_27_0_2_1);
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
Assert.IsTrue (b.Build (proj), "first build should have succeeded");

Expand All @@ -1415,30 +1415,31 @@ public void Issue2205 ([Values (false, true)] bool useAapt2)
{
var proj = new XamarinAndroidApplicationProject ();
proj.SetProperty ("AndroidUseAapt2", useAapt2.ToString ());
proj.Packages.Add (KnownPackages.Android_Arch_Core_Common_26_1_0);
proj.Packages.Add (KnownPackages.Android_Arch_Lifecycle_Common_26_1_0);
proj.Packages.Add (KnownPackages.Android_Arch_Lifecycle_Runtime_26_1_0);
proj.Packages.Add (KnownPackages.AndroidSupportV4_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportCompat_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportCoreUI_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportCoreUtils_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportDesign_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportFragment_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportMediaCompat_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportV7AppCompat_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportV7CardView_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportV7MediaRouter_27_0_2_1);
proj.Packages.Add (KnownPackages.SupportV7RecyclerView_27_0_2_1);
proj.Packages.Add (KnownPackages.Xamarin_GooglePlayServices_Gcm);
proj.Packages.Add (KnownPackages.Xamarin_GooglePlayServices_Tasks);
proj.Packages.Add (KnownPackages.Xamarin_GooglePlayServices_Iid);
proj.Packages.Add (KnownPackages.Xamarin_GooglePlayServices_Basement);
proj.Packages.Add (KnownPackages.Xamarin_GooglePlayServices_Base);
proj.PackageReferences.Add (KnownPackages.Android_Arch_Core_Common_26_1_0);
proj.PackageReferences.Add (KnownPackages.Android_Arch_Lifecycle_Common_26_1_0);
proj.PackageReferences.Add (KnownPackages.Android_Arch_Lifecycle_Runtime_26_1_0);
proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportCompat_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportCoreUI_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportCoreUtils_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportDesign_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportFragment_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportMediaCompat_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportV7AppCompat_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportV7CardView_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportV7MediaRouter_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportV7RecyclerView_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.Xamarin_GooglePlayServices_Gcm);
proj.PackageReferences.Add (KnownPackages.Xamarin_GooglePlayServices_Tasks);
proj.PackageReferences.Add (KnownPackages.Xamarin_GooglePlayServices_Iid);
proj.PackageReferences.Add (KnownPackages.Xamarin_GooglePlayServices_Basement);
proj.PackageReferences.Add (KnownPackages.Xamarin_GooglePlayServices_Base);
proj.OtherBuildItems.Add (new BuildItem ("GoogleServicesJson", "googleservices.json") {
Encoding = Encoding.ASCII,
TextContent = () => @"{
""project_info"": {
""project_number"": ""12351255213413432"",
""project_id"": ""12341234-app"",
""project_id"": ""12341234-app""
},
""client"": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void BuildAarBindigLibraryWithNuGetPackageOfJar (string classParser)
UseLatestPlatformSdk = true,
IsRelease = true,
};
proj.Packages.Add (KnownPackages.AndroidSupportV4_22_1_1_1);
proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_22_1_1_1);
proj.Jars.Add (new AndroidItem.LibraryProjectZip ("Jars\\android-crop-1.0.1.aar") {
WebContent = "https://jcenter.bintray.com/com/soundcloud/android/android-crop/1.0.1/android-crop-1.0.1.aar"
});
Expand All @@ -109,7 +109,7 @@ public void BuildLibraryZipBindigLibraryWithAarOfJar (string classParser)
IsRelease = true,
};
proj.AndroidClassParser = classParser;
proj.Packages.Add (KnownPackages.AndroidSupportV4_22_1_1_1);
proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_22_1_1_1);
proj.Jars.Add (new AndroidItem.LibraryProjectZip ("Jars\\aFileChooserBinaries.zip") {
WebContentFileNameFromAzure = "aFileChooserBinaries.zip"
});
Expand Down Expand Up @@ -384,7 +384,7 @@ public void RemoveEventHandlerResolution ()
<attr path=""/api/package[@name='com.actionbarsherlock.view']"" name=""managedName"">Xamarin.ActionbarSherlockBinding.Views</attr>
</metadata>",
};
binding.Packages.Add (KnownPackages.AndroidSupportV4_22_1_1_1);
binding.PackageReferences.Add (KnownPackages.AndroidSupportV4_22_1_1_1);
using (var bindingBuilder = CreateDllBuilder (Path.Combine ("temp", "RemoveEventHandlerResolution", "Binding"))) {
Assert.IsTrue (bindingBuilder.Build (binding), "binding build should have succeeded");
}
Expand Down
Loading

0 comments on commit d0e86e8

Please sign in to comment.