Open glennc opened 5 years ago
@anurse @davidfowl
Right now Microsoft.Extensions.Hosting cannot be added to Xamarin Android project (I assume that's for Xamarin iOS as well, but cannot test). There 2 offending libraries
error XA2002: Can not resolve reference: `System.Diagnostics.EventLog`, referenced by `Microsoft.Extensions.Logging.EventLog`. Please add a NuGet package or assembly reference for `System.Diagnostics.EventLog`, or remove the reference to `Microsoft.Extensions.Logging.EventLog`.
error XA2002: Can not resolve reference: `Microsoft.Bcl.AsyncInterfaces`, referenced by `System.Text.Json`. Please add a NuGet package or assembly reference for `Microsoft.Bcl.AsyncInterfaces`, or remove the reference to `System.Text.Json`.
Adding Microsoft.Bcl.AsyncInterfaces
and adding System.Diagnostics.EventLog
to the XamarinAndroid project does not remove any of these two errors.
Any solution to this problem?
I can build successfully without any issues locally in VisualStudio.16.Preview/16.4.0-pre.2.0+29411.138
(I have not tried with a non-preview version), but in the Azure DevOps hosted agent (Windows) which uses VisualStudio/16.2.0+29123.88
I do get the exact same issues:
Here's something I did notice in the run of csc.exe
on AzDo:
...
/reference:d:\a\1\s\artifacts\build\obj\base\.nuget\packages\microsoft.bcl.asyncinterfaces\1.0.0\ref\netstandard2.1\Microsoft.Bcl.AsyncInterfaces.dll
...
/reference:d:\a\1\s\artifacts\build\obj\base\.nuget\packages\system.diagnostics.eventlog\4.6.0\ref\netstandard2.0\System.Diagnostics.EventLog.dll
...
Seeing the \ref\
here reminded me about https://github.com/xamarin/xamarin-android/issues/2534 which leads us to https://github.com/xamarin/xamarin-android/issues/2674... but I don't really know what's happening here 😅
Additionally https://github.com/xamarin/xamarin-android/issues/3723 might be of interest, which is fixed in the VS preview with preview Xamarin.Android... It says that the fix is also included in Xamarin.Android 10.0.3.0, but it looks like the AzDo agent is using it according to its build logs:
Found Xamarin.Android 10.0.3.0
Additionally this same issue was raised in https://github.com/aspnet/Extensions/issues/2182, too.
Is this something that should be raised with https://github.com/xamarin/xamarin-android instead? Is it related to the other issues I linked on the Xamarin.Android repo?
BTW, I was able to get a server running on android by providing a cancellable cancel token and using the RunAsync
method..
var src = new CancellationTokenSource();
var host = WebHost.CreateDefaultBuilder(null)
.UseKestrel(o => {
//...
})
.UseStartup<Startup>()
.Build();
await host.RunAsync(src.Token);
Any new information/workarounds/fixes? I followed the James aspcore DI into xamarin apps post (https://montemagno.com/add-asp-net-cores-dependency-injection-into-xamarin-apps-with-hostbuilder/) Works great but it won't build on the hosted agent :-(
@rneeft can you share what error(s) you're getting?
I get the following errors:
Error XA2002 : Can Not resolve reference: Microsoft.Bcl.AsyncInterfaces
, referenced by Microsoft.Extensions.DependencyInjection
. Please add a NuGet package Or assembly reference for Microsoft.Bcl.AsyncInterfaces
, Or remove the reference to Microsoft.Extensions.DependencyInjection
.
Error XA2002 : Can Not resolve reference: Microsoft.Bcl.AsyncInterfaces
, referenced by Microsoft.Extensions.Hosting.Abstractions
. Please add a NuGet package Or assembly reference for Microsoft.Bcl.AsyncInterfaces
, Or remove the reference to Microsoft.Extensions.Hosting.Abstractions
.
Error XA2002 : Can Not resolve reference: Microsoft.Bcl.AsyncInterfaces
, referenced by Microsoft.Extensions.Hosting
. Please add a NuGet package Or assembly reference for Microsoft.Bcl.AsyncInterfaces
, Or remove the reference to Microsoft.Extensions.Hosting
.
Error XA2002 : Can Not resolve reference: System.Diagnostics.EventLog
, referenced by Microsoft.Extensions.Logging.EventLog
. Please add a NuGet package Or assembly reference for System.Diagnostics.EventLog
, Or remove the reference to Microsoft.Extensions.Logging.EventLog
.
Error XA2002 : Can Not resolve reference: Microsoft.Bcl.AsyncInterfaces
, referenced by System.Text.Json
. Please add a NuGet package Or assembly reference for Microsoft.Bcl.AsyncInterfaces
, Or remove the reference to System.Text.Json
.
See the attachment for the full build log log.txt
Part of the YAML build:
jobs:
- job: Build
pool:
vmImage: 'windows-latest'
steps:
- task: NuGetToolInstaller@0
displayName: 'Use NuGet 4.4.1'
inputs:
versionSpec: 4.4.1
- task: NuGetToolInstaller@0
inputs:
versionSpec: '5.3.0'
enabled: false
- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'select'
restoreDirectory: '../Packages'
- task: VSBuild@1
displayName: 'Build solution'
inputs:
solution: '**/*.sln'
msbuildArgs: '/p:AppxBundle=Never /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:publishUrl=$(build.artifactstagingdirectory)\Website'
platform: 'any cpu'
configuration: 'release'
I hope it helps. Let me know when you need something more.
Hmm so far it looks OK to me. Can you show what the affected CSPROJ looks like? It's presumably one of the Xamarin.Forms projects.
XamarinForms.cspoj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Chroomsoft.Top2000.Mobile</AssemblyName>
<RootNamespace>Chroomsoft.Top2000.Mobile</RootNamespace>
<NullableReferenceTypes>true</NullableReferenceTypes>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>pdbonly</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<None Remove="appsettings.json" />
<None Remove="Database\Top2000.db" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="appsettings.json" />
<EmbeddedResource Include="Database\Top2000.db" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="2.6.4" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="2.6.4" />
<PackageReference Include="Microsoft.CSharp" Version="4.6.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Xamarin.Forms" Version="4.4.0.991265" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Base\Access\SQLite\Access.SQLite\Access.SQLite.csproj" />
<ProjectReference Include="..\..\..\Base\Top2000\Top2000.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="Java.Interop">
<HintPath>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Java.Interop.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Update="Globalisation\AppResources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>AppResources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="About\AboutView.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="AppShell.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Globalisation\AppResources.fr.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Globalisation\AppResources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>AppResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Globalisation\AppResources.en.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>AppResources.en.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Search\SearchView.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="SelectDate\SelectDateView.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Settings\SettingsView.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="SingleTrack\SingleTrackView.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="ViewByDate\ViewByDateView.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="YearOverview\YearOverviewView.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
XamarinForms.Android.csproj
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A25989B6-2A0E-471C-AB01-A478DA574BEE}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TemplateGuid>{c9e5eea5-ca05-42a1-839b-61506e0a37df}</TemplateGuid>
<OutputType>Library</OutputType>
<RootNamespace>Chroomsoft.Top2000.Mobile.Droid</RootNamespace>
<AssemblyName>Chroomsoft.Top2000.Mobile.Droid</AssemblyName>
<AndroidApplication>True</AndroidApplication>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
<AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<AndroidKeyStore>false</AndroidKeyStore>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>None</AndroidLinkMode>
<AndroidSupportedAbis />
<AndroidLinkSkip>System.Diagnostics.EventLog</AndroidLinkSkip>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
<AndroidUseAapt2>false</AndroidUseAapt2>
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
<AndroidSupportedAbis />
<MandroidI18n />
<AndroidPackageFormat>apk</AndroidPackageFormat>
<AndroidKeyStore>false</AndroidKeyStore>
<AndroidSigningKeyStore>
</AndroidSigningKeyStore>
<AndroidSigningKeyAlias>
</AndroidSigningKeyAlias>
<AndroidSigningStorePass>
</AndroidSigningStorePass>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Android" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AppCenter.Analytics">
<Version>2.6.4</Version>
</PackageReference>
<PackageReference Include="Microsoft.AppCenter.Crashes">
<Version>2.6.4</Version>
</PackageReference>
<PackageReference Include="Microsoft.CSharp">
<Version>4.6.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Hosting">
<Version>3.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Http">
<Version>3.1.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="4.4.0.991265" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.3" />
</ItemGroup>
<ItemGroup>
<Compile Include="Controls\ProgressRingRenderer.cs" />
<Compile Include="Globalisation\LocalisationService.cs" />
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SplashActivity.cs" />
<Compile Include="Top2000SQLiteDatabaseFactory.cs" />
</ItemGroup>
<ItemGroup>
<AndroidAsset Include="Assets\Symbols.ttf" />
<None Include="Resources\AboutResources.txt" />
<None Include="Assets\AboutAssets.txt" />
<None Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\Tabbar.xml" />
<AndroidResource Include="Resources\layout\Toolbar.xml" />
<AndroidResource Include="Resources\values\styles.xml" />
<AndroidResource Include="Resources\values\colors.xml" />
<AndroidResource Include="Resources\mipmap-anydpi-v26\icon.xml" />
<AndroidResource Include="Resources\mipmap-anydpi-v26\icon_round.xml" />
<AndroidResource Include="Resources\mipmap-hdpi\top2000icon.png" />
<AndroidResource Include="Resources\mipmap-mdpi\top2000icon.png" />
<AndroidResource Include="Resources\mipmap-xhdpi\top2000icon.png" />
<AndroidResource Include="Resources\mipmap-xxhdpi\top2000icon.png" />
<AndroidResource Include="Resources\mipmap-xxxhdpi\top2000icon.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\drawable-hdpi\" />
<Folder Include="Resources\drawable-mdpi\" />
<Folder Include="Resources\drawable-xhdpi\" />
<Folder Include="Resources\drawable-xxhdpi\" />
<Folder Include="Resources\drawable-xxxhdpi\" />
<Folder Include="Resources\raw\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Base\Access\SQLite\Access.SQLite\Access.SQLite.csproj">
<Project>{e13d6870-170a-4b4f-a2d2-5f14a0e3bdc6}</Project>
<Name>Access.SQLite</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Base\Top2000\Top2000.csproj">
<Project>{d009ccde-77ba-4b62-a79b-02bc6d823e50}</Project>
<Name>Top2000</Name>
</ProjectReference>
<ProjectReference Include="..\XamarinForms\XamarinForms.csproj">
<Project>{4BD9C2AD-0167-45B7-9B05-D46BBCC4ED78}</Project>
<Name>XamarinForms</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\Up.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\splash_screen.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\nl.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\fr.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\en.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\header.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\mipmap-hdpi\top2000iconRound.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\mipmap-mdpi\top2000iconRound.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\mipmap-xhdpi\top2000iconRound.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\mipmap-xxhdpi\top2000iconRound.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\mipmap-xxxhdpi\top2000iconRound.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\mipmap-hdpi\top2000splash.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\mipmap-mdpi\top2000splash.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\mipmap-xhdpi\top2000splash.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\mipmap-xxhdpi\top2000splash.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\mipmap-xxxhdpi\top2000splash.png" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>
Thank you, I will take a look in the morning,
@rneeft the only thing I can think of right now is that maybe there's an issue specific to v3.1 of these packages?
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.0" />
What if you try 3.0.0?
@Eilon I tried to move from 3.1.0 to 3.0.0 resulting into fewer errors. The only two left are:
System.Diagnostics.EventLog
, referenced by Microsoft.Extensions.Logging.EventLog
. Please add a NuGet package or assembly reference for System.Diagnostics.EventLog
, or remove the reference to Microsoft.Extensions.Logging.EventLog
.Microsoft.Bcl.AsyncInterfaces
, referenced by System.Text.Json
. Please add a NuGet package or assembly reference for Microsoft.Bcl.AsyncInterfaces
, or remove the reference to System.Text.Json
.I'll tried to work on this some more the coming weekend. Thanks for the help. If you have any more tips please let me know. I'll keep posting any new development from my side.
Hi All,
I still don't have any luck from my side. To help troubleshoot and isolate the issue, I created a GitHub repository and a public Azure DevOps Team Project with a (YAML) build pipeline.
I hope the issue can be fixed because I love the way it is working (except for the build off course).
Rick
I have the same error regarding Can not resolve reference: Microsoft.Bcl.AsyncInterfaces
when building the Xamarin.Android project on hosted windows2019 of Azure DevOps. The package has been installed correctly and I can build it on my local machine.
@yanxiaodi You can track work on that issue at Xamarin https://github.com/xamarin/xamarin-android/issues/4074 If you really desperate you can try build Xamarin from https://github.com/xamarin/xamarin-android/pull/4171
@yanxiaodi I had the same issue. There are 2 workarounds. Use net standard 2.1, so you don’t need explicitly install the package. Or make sure you restore your packages in C:/users/username/.nuget/packages
@kant2002 @VladislavAntonyuk many thanks for your help. But we are using Azure DevOps Hosted VS1029 to build the project so cannot manually restore the packages. It is hard to update to .net standard 2.1 because that would impact some other projects, which means more risks. I have to revert to the old packages at the moment.
I have the "Can not resolve reference: Microsoft.Bcl.AsyncInterfaces" issue also. Using .NET Standard 2.1 nor restoring packages to C:/users/username/.nuget/packages fixes things.
@DAMcK-TREC Can you try suggestion here? https://github.com/xamarin/xamarin-android/issues/4074#issuecomment-592935384
I believe the issue is fixed. My test project is building fine on the build server now :)
I'm trying to use Generic Host in my Android app.
I'm calling Host.CreateDefaultHost()
to initiate it.
When I call host.Start()
, it calls ConsoleLifetime.WaitForStartAsync(token)
under the hood, which calls Console.CancelKeyPress += OnCancelKeyPress;
, that throws a PlatformNotSupportedException
.
I copied the ConsoleLifetime
file to my project, and removed that line.
Then at service config I added it to the service registration:
servicesBuilder.AddSingleton<IHostLifetime, AppConsoleLifetime>();
Works like a charm.
Please look at PR dotnet/extensions#3208 for a sample of having another console option that allows ignoring the cancel event.
Triage: Transferring this issue to runtime to keep on the future backlog, but there's currently no concrete plan on where (Xamarin, runtime, etc.), when or if the work will happen :).
I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label.
I'm willing to contribute.
Any work on this issue? seems is keeping us of using the Host on Android
This is for tracking the items we've talked about to support Xamarin development better with GenericHost.