Skip to content

Commit

Permalink
[One .NET] exclude Microsoft.AspNetCore.App.Runtime.linux-* packages (#…
Browse files Browse the repository at this point in the history
…6207)

Context: dotnet/sdk#19891

If you `dotnet new android` and `dotnet build` it without a
`NuGet.config` you hit:

    error NU1102: Unable to find package Microsoft.AspNetCore.App.Runtime.linux-arm64 with version (= 6.0.0-rc.1.21417.2)

I found I could workaround the problem by removing `linux-*` packages
at a certain point during the build:

    <Target Name="_RemoveLinuxFrameworkReferences"
        AfterTargets="ProcessFrameworkReferences">
      <ItemGroup>
        <_ProblematicRIDs Include="linux-arm;linux-arm64;linux-x86;linux-x64" />
        <PackageDownload Remove="Microsoft.AspNetCore.App.Runtime.%(_ProblematicRIDs.Identity)" />
        <PackageDownload Remove="Microsoft.NETCore.App.Host.%(_ProblematicRIDs.Identity)" />
      </ItemGroup>
    </Target>

With this target in place, I can build projects without a
`NuGet.config` file. Let's put this workaround in place until we have
another solution for dotnet/sdk#19891.

To validate these changes, I removed any instances of the `dotnet6`
feed in our MSBuild tests.
  • Loading branch information
jonathanpeppers committed Aug 20, 2021
1 parent c00a5a1 commit d8fca1c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ _ResolveAssemblies MSBuild target.
<UsingTask TaskName="Xamarin.Android.Tasks.ProcessNativeLibraries" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" />
<UsingTask TaskName="Xamarin.Android.Tasks.StripNativeLibraries" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" />

<!-- HACK: workaround for: https://github.com/dotnet/sdk/issues/19891 -->
<Target Name="_RemoveLinuxFrameworkReferences"
AfterTargets="ProcessFrameworkReferences">
<ItemGroup>
<_ProblematicRIDs Include="linux-arm;linux-arm64;linux-x86;linux-x64" />
<PackageDownload Remove="Microsoft.AspNetCore.App.Runtime.%(_ProblematicRIDs.Identity)" />
<PackageDownload Remove="Microsoft.NETCore.App.Host.%(_ProblematicRIDs.Identity)" />
</ItemGroup>
</Target>

<PropertyGroup Condition=" '$(_ComputeFilesToPublishForRuntimeIdentifiers)' == 'true' ">
<OutputPath Condition=" '$(_OuterOutputPath)' != '' ">$(_OuterOutputPath)</OutputPath>
<OutDir Condition=" '$(_OuterOutputPath)' != '' ">$(_OuterOutputPath)</OutDir>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,16 @@ public void DotNetBuild (string runtimeIdentifiers, bool isRelease, bool aot)
var proj = new XASdkProject {
IsRelease = isRelease,
ExtraNuGetConfigSources = {
"https://pkgs.dev.azure.com/azure-public/vside/_packaging/xamarin-impl/nuget/v3/index.json"
// 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.2.0.7-net6preview01" },
new Package { Id = "Microsoft.AspNetCore.Components.WebView", Version = "6.0.0-preview.5.21301.17" },
new Package { Id = "Microsoft.Extensions.FileProviders.Embedded", Version = "6.0.0-preview.6.21306.3" },
new Package { Id = "Microsoft.JSInterop", Version = "6.0.0-preview.6.21306.3" },
new Package { Id = "System.Text.Json", Version = "6.0.0-preview.7.21323.3" },
new Package { Id = "Xamarin.AndroidX.AppCompat", Version = "1.3.1.1" },
// Using * here, so we explicitly get newer packages
new Package { Id = "Microsoft.AspNetCore.Components.WebView", Version = "6.0.0-*" },
new Package { Id = "Microsoft.Extensions.FileProviders.Embedded", Version = "6.0.0-*" },
new Package { Id = "Microsoft.JSInterop", Version = "6.0.0-*" },
new Package { Id = "System.Text.Json", Version = "6.0.0-*" },
},
Sources = {
new BuildItem ("EmbeddedResource", "Foo.resx") {
Expand Down Expand Up @@ -637,32 +639,24 @@ public void MauiTargetFramework ([Values ("net6.0-android", "net6.0-android30",
var library = new XASdkProject (outputType: "Library") {
TargetFramework = targetFramework,
};
library.ExtraNuGetConfigSources.Add ("https://pkgs.dev.azure.com/azure-public/vside/_packaging/xamarin-impl/nuget/v3/index.json");
library.Sources.Clear ();
library.Sources.Add (new BuildItem.Source ("Foo.cs") {
TextContent = () =>
@"using Microsoft.Maui;
using Microsoft.Maui.Handlers;
@"public abstract partial class ViewHandler<TVirtualView, TNativeView> { }
public abstract class Foo<TVirtualView, TNativeView> : AbstractViewHandler<TVirtualView, TNativeView>
public interface IView { }
public abstract class Foo<TVirtualView, TNativeView> : ViewHandler<TVirtualView, TNativeView>
where TVirtualView : class, IView
#if ANDROID
where TNativeView : Android.Views.View
#else
where TNativeView : class
#endif
{
protected Foo (PropertyMapper mapper) : base(mapper)
{
#if ANDROID
var t = this.Context;
#endif
}
}",
});

library.PackageReferences.Add (new Package { Id = "Microsoft.Maui.Core", Version = "6.0.100-preview.3.269" });

var dotnet = CreateDotNetBuilder (library);
Assert.IsTrue (dotnet.Build (), $"{library.ProjectName} should succeed");
dotnet.AssertHasNoWarnings ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,12 @@ public void CopyNuGetConfig (string relativeDirectory)
if (File.Exists (repoNuGetConfig) && !File.Exists (projNugetConfig)) {
Directory.CreateDirectory (Path.GetDirectoryName (projNugetConfig));
File.Copy (repoNuGetConfig, projNugetConfig, overwrite: true);
// Write additional sources to NuGet.config if needed
if (ExtraNuGetConfigSources != null) {
var doc = XDocument.Load (projNugetConfig);
AddNuGetConfigSources (doc);
doc.Save (projNugetConfig);
}

var doc = XDocument.Load (projNugetConfig);
AddNuGetConfigSources (doc);

// Set a local PackageReference installation folder if specified
if (!string.IsNullOrEmpty (GlobalPackagesFolder)) {
var doc = XDocument.Load (projNugetConfig);
XElement gpfElement = doc.Descendants ().FirstOrDefault (c => c.Name.LocalName.ToLowerInvariant () == "add"
&& c.Attributes ().Any (a => a.Name.LocalName.ToLowerInvariant () == "key" && a.Value.ToLowerInvariant () == "globalpackagesfolder"));
if (gpfElement != default (XElement)) {
Expand All @@ -442,18 +439,37 @@ public void CopyNuGetConfig (string relativeDirectory)
doc.Root.Add (configParentElement);
}
}
doc.Save (projNugetConfig);
}

doc.Save (projNugetConfig);
}
}

/// <summary>
/// Updates a NuGet.config based on sources in ExtraNuGetConfigSources
/// Removes the dotnet6 source, which should not be needed by tests
/// </summary>
protected void AddNuGetConfigSources (XDocument doc)
{
const string elementName = "packageSources";
XElement pkgSourcesElement = doc.Root.Elements ().FirstOrDefault (d => string.Equals (d.Name.LocalName, elementName, StringComparison.OrdinalIgnoreCase));
if (pkgSourcesElement == null) {
doc.Root.Add (pkgSourcesElement= new XElement (elementName));
}

// Remove dotnet6 feed
foreach (XElement element in pkgSourcesElement.Elements ()) {
XAttribute value = element.Attribute ("value");
if (value != null && value.Value == "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json") {
element.Remove ();
break;
}
}

// Add extra sources
if (ExtraNuGetConfigSources == null)
return;
int sourceIndex = 0;
XElement pkgSourcesElement = doc.Descendants ().FirstOrDefault (d => d.Name.LocalName.ToLowerInvariant () == "packagesources");
foreach (var source in ExtraNuGetConfigSources) {
var sourceElement = new XElement ("add");
sourceElement.SetAttributeValue ("key", $"testsource{++sourceIndex}");
Expand Down

0 comments on commit d8fca1c

Please sign in to comment.