diff --git a/build-tools/automation/azure-pipelines-apidocs.yaml b/build-tools/automation/azure-pipelines-apidocs.yaml index 642965e8147..9340419e86a 100644 --- a/build-tools/automation/azure-pipelines-apidocs.yaml +++ b/build-tools/automation/azure-pipelines-apidocs.yaml @@ -131,7 +131,7 @@ extends: inputs: forceReinstallCredentialProvider: true - - script: dotnet tool update -v:n boots --version 1.1.0.36 --add-source "https://api.nuget.org/v3/index.json" --global + - script: dotnet tool update -v:n boots --version 1.1.0.36 --global displayName: Install boots - script: boots https://download.mono-project.com/archive/6.12.0/macos-10-universal/MonoFramework-MDK-6.12.0.188.macos10.xamarin.universal.pkg diff --git a/build-tools/automation/azure-pipelines.yaml b/build-tools/automation/azure-pipelines.yaml index 61be4053073..571a8443945 100644 --- a/build-tools/automation/azure-pipelines.yaml +++ b/build-tools/automation/azure-pipelines.yaml @@ -188,7 +188,7 @@ extends: - template: /build-tools/automation/yaml-templates/run-dotnet-preview.yaml@self parameters: command: new - arguments: maui -o $(Build.StagingDirectory)/MauiTestProj + arguments: maui -o $(Build.StagingDirectory)/MauiTestProj --no-restore xaSourcePath: $(Build.SourcesDirectory)/android displayName: Create MAUI template continueOnError: false diff --git a/build-tools/automation/yaml-templates/build-windows.yaml b/build-tools/automation/yaml-templates/build-windows.yaml index 713f484e92c..eec9fa2a776 100644 --- a/build-tools/automation/yaml-templates/build-windows.yaml +++ b/build-tools/automation/yaml-templates/build-windows.yaml @@ -104,13 +104,15 @@ stages: displayName: Test dotnet-local.cmd - create template inputs: filename: dotnet-local.cmd - arguments: new android -o $(Build.StagingDirectory)/LocalWorkloadTest + arguments: new android -o "$(Build.StagingDirectory)\LocalWorkloadTest" - task: BatchScript@1 displayName: Test dotnet-local.cmd - build template inputs: filename: dotnet-local.cmd - arguments: build -v:n $(Build.StagingDirectory)/LocalWorkloadTest + arguments: >- + build -v:n "$(Build.StagingDirectory)\LocalWorkloadTest" + -p:RestoreConfigFile="$(System.DefaultWorkingDirectory)\NuGet.config" # Pack .nupkgs and extract workload packs to dotnet preview test directory - template: /build-tools/automation/yaml-templates/run-dotnet-preview.yaml diff --git a/build-tools/automation/yaml-templates/variables.yaml b/build-tools/automation/yaml-templates/variables.yaml index 9fa934e62db..23efd8699c9 100644 --- a/build-tools/automation/yaml-templates/variables.yaml +++ b/build-tools/automation/yaml-templates/variables.yaml @@ -80,3 +80,11 @@ variables: value: true - name: DOTNET_GENERATE_ASPNET_CERTIFICATE value: false +# Fix network isolation requirements +# See https://devdiv.visualstudio.com/DevDiv/_git/Xamarin.yaml-templates/pullrequest/750402 +- name: DOTNET_CLI_WORKLOAD_UPDATE_NOTIFY_DISABLE + value: 'true' +- name: DOTNET_SDK_VULNERABILITY_CHECK_DISABLE + value: 'true' +- name: NuGetAudit + value: 'false' diff --git a/src/Microsoft.Android.Templates/android-bindinglib/.template.config/dotnetcli.host.json b/src/Microsoft.Android.Templates/android-bindinglib/.template.config/dotnetcli.host.json new file mode 100644 index 00000000000..f0a41abf603 --- /dev/null +++ b/src/Microsoft.Android.Templates/android-bindinglib/.template.config/dotnetcli.host.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/dotnetcli.host", + "symbolInfo": { + "skipRestore": { + "longName": "no-restore", + "shortName": "" + } + } +} diff --git a/src/Microsoft.Android.Templates/android-bindinglib/.template.config/template.json b/src/Microsoft.Android.Templates/android-bindinglib/.template.config/template.json index c6e8c6ca8ee..13dcc6bc077 100644 --- a/src/Microsoft.Android.Templates/android-bindinglib/.template.config/template.json +++ b/src/Microsoft.Android.Templates/android-bindinglib/.template.config/template.json @@ -22,6 +22,12 @@ "datatype": "string", "replaces": "SUPPORTED_OS_PLATFORM_VERSION", "defaultValue": "24" + }, + "skipRestore": { + "type": "parameter", + "datatype": "bool", + "description": "If specified, skips the automatic restore of the project on create.", + "defaultValue": "false" } }, "defaultName": "AndroidBinding1" diff --git a/src/Microsoft.Android.Templates/android-wear/.template.config/dotnetcli.host.json b/src/Microsoft.Android.Templates/android-wear/.template.config/dotnetcli.host.json new file mode 100644 index 00000000000..f0a41abf603 --- /dev/null +++ b/src/Microsoft.Android.Templates/android-wear/.template.config/dotnetcli.host.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/dotnetcli.host", + "symbolInfo": { + "skipRestore": { + "longName": "no-restore", + "shortName": "" + } + } +} diff --git a/src/Microsoft.Android.Templates/android-wear/.template.config/template.json b/src/Microsoft.Android.Templates/android-wear/.template.config/template.json index 912b864de55..f098607fcd3 100644 --- a/src/Microsoft.Android.Templates/android-wear/.template.config/template.json +++ b/src/Microsoft.Android.Templates/android-wear/.template.config/template.json @@ -35,6 +35,12 @@ "datatype": "string", "replaces": "SUPPORTED_OS_PLATFORM_VERSION", "defaultValue": "24" + }, + "skipRestore": { + "type": "parameter", + "datatype": "bool", + "description": "If specified, skips the automatic restore of the project on create.", + "defaultValue": "false" } }, "defaultName": "AndroidApp1" diff --git a/src/Microsoft.Android.Templates/android/.template.config/dotnetcli.host.json b/src/Microsoft.Android.Templates/android/.template.config/dotnetcli.host.json new file mode 100644 index 00000000000..f0a41abf603 --- /dev/null +++ b/src/Microsoft.Android.Templates/android/.template.config/dotnetcli.host.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/dotnetcli.host", + "symbolInfo": { + "skipRestore": { + "longName": "no-restore", + "shortName": "" + } + } +} diff --git a/src/Microsoft.Android.Templates/android/.template.config/template.json b/src/Microsoft.Android.Templates/android/.template.config/template.json index 8ec941ba0a1..a7d3c05c87b 100644 --- a/src/Microsoft.Android.Templates/android/.template.config/template.json +++ b/src/Microsoft.Android.Templates/android/.template.config/template.json @@ -35,6 +35,12 @@ "datatype": "string", "replaces": "SUPPORTED_OS_PLATFORM_VERSION", "defaultValue": "24" + }, + "skipRestore": { + "type": "parameter", + "datatype": "bool", + "description": "If specified, skips the automatic restore of the project on create.", + "defaultValue": "false" } }, "defaultName": "AndroidApp1" diff --git a/src/Microsoft.Android.Templates/androidlib/.template.config/dotnetcli.host.json b/src/Microsoft.Android.Templates/androidlib/.template.config/dotnetcli.host.json new file mode 100644 index 00000000000..f0a41abf603 --- /dev/null +++ b/src/Microsoft.Android.Templates/androidlib/.template.config/dotnetcli.host.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/dotnetcli.host", + "symbolInfo": { + "skipRestore": { + "longName": "no-restore", + "shortName": "" + } + } +} diff --git a/src/Microsoft.Android.Templates/androidlib/.template.config/template.json b/src/Microsoft.Android.Templates/androidlib/.template.config/template.json index 517bd32482e..506b4c4a10f 100644 --- a/src/Microsoft.Android.Templates/androidlib/.template.config/template.json +++ b/src/Microsoft.Android.Templates/androidlib/.template.config/template.json @@ -22,6 +22,12 @@ "datatype": "string", "replaces": "SUPPORTED_OS_PLATFORM_VERSION", "defaultValue": "24" + }, + "skipRestore": { + "type": "parameter", + "datatype": "bool", + "description": "If specified, skips the automatic restore of the project on create.", + "defaultValue": "false" } }, "defaultName": "AndroidLib1" diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs index a895295d526..eb7ce433760 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs @@ -33,10 +33,6 @@ public void DotNetBuild (string runtimeIdentifiers, bool isRelease, bool aot, bo ProjectName = "Test Me", RootNamespace = "Test.Me", EnableDefaultItems = true, - ExtraNuGetConfigSources = { - // Microsoft.AspNetCore.Components.WebView is not in dotnet-public - "https://api.nuget.org/v3/index.json", - }, PackageReferences = { new Package { Id = "Xamarin.AndroidX.AppCompat", Version = "1.3.1.1" }, // Using * here, so we explicitly get newer packages diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/CodeBehindTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/CodeBehindTests.cs index da088199ffd..19ff0be59f1 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/CodeBehindTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/CodeBehindTests.cs @@ -691,7 +691,7 @@ string PrepareProject (string testName) CopyRecursively (CommonSampleLibraryRootDirectory, Path.Combine (tempRoot, CommonSampleLibraryName), ignore); CopyFile (Path.Combine (XABuildPaths.TopDirectory, "Directory.Build.props"), Path.Combine (tempRoot, "Directory.Build.props" )); var project = new XamarinAndroidApplicationProject (); - project.CopyNuGetConfig (Path.Combine (tempRoot, "NuGet.config")); + project.CopyNuGetConfig (tempRoot); return temporaryProjectPath; } diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/FilterAssembliesTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/FilterAssembliesTests.cs index 7eeba328dab..e60bfe8f56b 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/FilterAssembliesTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/FilterAssembliesTests.cs @@ -14,6 +14,8 @@ namespace Xamarin.Android.Build.Tests [TestFixture] public class FilterAssembliesTests : BaseTest { + const string DotNetPublicPackageBaseAddress = "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/flat2"; + string tempDirectory; [SetUp] @@ -32,6 +34,20 @@ public void TearDown () Task DownloadFromNuGet (string url, string filename = "") => Task.Factory.StartNew (() => new DownloadedCache ().GetAsFile (url, filename)); + static string GetPackageUrl (string packageId, string version) + { + var lowercaseId = packageId.ToLowerInvariant (); + var lowercaseVersion = version.ToLowerInvariant (); + return $"{DotNetPublicPackageBaseAddress}/{lowercaseId}/{lowercaseVersion}/{lowercaseId}.{lowercaseVersion}.nupkg"; + } + + [Test] + public void PackageUrlIsLowercase () + { + var actual = GetPackageUrl ("Package.ID", "1.0.0-RC1"); + Assert.AreEqual ($"{DotNetPublicPackageBaseAddress}/package.id/1.0.0-rc1/package.id.1.0.0-rc1.nupkg", actual); + } + async Task GetAssembliesFromNuGet (string url, string filename, string path) { var assemblies = new List (); @@ -65,7 +81,7 @@ string [] Run (params string [] assemblies) public async Task CircleImageView () { var assemblies = await GetAssembliesFromNuGet ( - "https://www.nuget.org/api/v2/package/Refractored.Controls.CircleImageView/1.0.1", + GetPackageUrl ("Refractored.Controls.CircleImageView", "1.0.1"), "Refractored.Controls.CircleImageView.1.0.1.nupkg", "lib/MonoAndroid10/"); var actual = Run (assemblies); @@ -77,7 +93,7 @@ public async Task CircleImageView () public async Task XamarinForms () { var assemblies = await GetAssembliesFromNuGet ( - "https://www.nuget.org/api/v2/package/Xamarin.Forms/3.6.0.220655", + GetPackageUrl ("Xamarin.Forms", "3.6.0.220655"), "Xamarin.Forms.3.6.0.220655.nupkg", "lib/MonoAndroid90/"); var actual = Run (assemblies); @@ -93,7 +109,7 @@ public async Task XamarinForms () public async Task GuavaListenableFuture () { var assemblies = await GetAssembliesFromNuGet ( - "https://www.nuget.org/api/v2/package/Xamarin.Google.Guava.ListenableFuture/1.0.0", + GetPackageUrl ("Xamarin.Google.Guava.ListenableFuture", "1.0.0"), "Xamarin.Google.Guava.ListenableFuture.1.0.0.nupkg", "lib/MonoAndroid50/"); var actual = Run (assemblies); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs index 5a2e4963605..d64e029ebe9 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Xml.Linq; using System.Reflection; using System.Text; using NUnit.Framework; @@ -32,18 +31,43 @@ public void DotNetNew ([Values ("android", "androidlib", "android-bindinglib", " TestOutputDirectories [TestContext.CurrentContext.Test.ID] = templatePath; var dotnet = new DotNetCLI (Path.Combine (templatePath, $"{templateName}.csproj")); - Assert.IsTrue (dotnet.New (template), $"`dotnet new {template}` should succeed"); + Assert.IsTrue (dotnet.New (template, noRestore: true), $"`dotnet new {template} --no-restore` should succeed"); + + var repoNuGetConfig = Path.Combine (XABuildPaths.TopDirectory, "NuGet.config"); + var projectNuGetConfig = Path.Combine (dotnet.ProjectDirectory, "NuGet.config"); + File.Copy (repoNuGetConfig, projectNuGetConfig); + FileAssert.AreEqual (repoNuGetConfig, projectNuGetConfig); + File.WriteAllBytes (Path.Combine (dotnet.ProjectDirectory, "foo.jar"), ResourceData.JavaSourceJarTestJar); Assert.IsTrue (dotnet.New ("android-activity"), "`dotnet new android-activity` should succeed"); Assert.IsTrue (dotnet.New ("android-layout", Path.Combine (dotnet.ProjectDirectory, "Resources", "layout")), "`dotnet new android-layout` should succeed"); // Debug build - Assert.IsTrue (dotnet.Build (parameters: new [] { "Configuration=Debug", "TrimmerSingleWarn=false" }), "`dotnet build` should succeed"); + Assert.IsTrue (dotnet.Build (parameters: GetBuildParameters ("Debug")), "`dotnet build` should succeed"); dotnet.AssertHasNoWarnings (); // Release build - Assert.IsTrue (dotnet.Build (parameters: new [] { "Configuration=Release", "TrimmerSingleWarn=false" }), "`dotnet build` should succeed"); + Assert.IsTrue (dotnet.Build (parameters: GetBuildParameters ("Release")), "`dotnet build` should succeed"); dotnet.AssertHasNoWarnings (); + + string [] GetBuildParameters (string configuration) + { + var parameters = new List { + $"Configuration={configuration}", + "TrimmerSingleWarn=false", + }; + if (template == "androidwear") { + var mavenTargets = Path.Combine ( + XABuildPaths.TopDirectory, + "src", + "Xamarin.Android.Build.Tasks", + "Tests", + "Xamarin.Android.Build.Tests", + "dotnet-public-maven.targets"); + parameters.Add ($"CustomAfterMicrosoftCommonTargets=\"{mavenTargets}\""); + } + return parameters.ToArray (); + } } static readonly object[] DotNetPackTargetFrameworks = new object[] { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/dotnet-public-maven.targets b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/dotnet-public-maven.targets new file mode 100644 index 00000000000..b29eaa03a16 --- /dev/null +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/dotnet-public-maven.targets @@ -0,0 +1,10 @@ + + + + + + + diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/DotNetCLI.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/DotNetCLI.cs index af412c959c5..5edef3715b2 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/DotNetCLI.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/DotNetCLI.cs @@ -104,13 +104,16 @@ protected bool Execute (params string [] args) return succeeded; } - public bool New (string template, string output = null) + public bool New (string template, string output = null, bool noRestore = false) { var arguments = new List { "new", template, "--output", $"\"{output ?? ProjectDirectory}\"", }; + if (noRestore) { + arguments.Add ("--no-restore"); + } return Execute (arguments.ToArray ()); } diff --git a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs index 054d3ab75dc..83af3ab9280 100644 --- a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs +++ b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs @@ -1668,9 +1668,6 @@ public static void logEvent(String eventName) {{ var proj = new XamarinAndroidApplicationProject { IsRelease = isRelease, - ExtraNuGetConfigSources = { - "https://api.nuget.org/v3/index.json", - }, OtherBuildItems = { new AndroidItem.TransformFile ("Transforms\\Metadata.xml") { TextContent = () => $@"Facebook",