dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.07k stars 4.69k forks source link

Support for Xamarin in GenericHost #35993

Open glennc opened 5 years ago

glennc commented 5 years ago

This is for tracking the items we've talked about to support Xamarin development better with GenericHost.

glennc commented 5 years ago

@anurse @davidfowl

kant2002 commented 5 years ago

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.

malukishtiaq commented 4 years ago

Any solution to this problem?

bddckr commented 4 years ago

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:

Azure DevOps build issues ``` 2019-11-02T11:05:23.2375752Z Adding assembly reference for Java.Interop, recursively... 2019-11-02T11:05:23.2385466Z Adding assembly reference for Microsoft.Extensions.Configuration.Abstractions, recursively... 2019-11-02T11:05:23.2390079Z Adding assembly reference for netstandard, recursively... 2019-11-02T11:05:23.3074609Z Adding assembly reference for System.Data, recursively... 2019-11-02T11:05:23.3176150Z Adding assembly reference for System.Transactions, recursively... 2019-11-02T11:05:23.3190534Z Adding assembly reference for System.Drawing.Common, recursively... 2019-11-02T11:05:23.3420945Z Adding assembly reference for System.IO.Compression, recursively... 2019-11-02T11:05:23.3500745Z Adding assembly reference for System.IO.Compression.FileSystem, recursively... 2019-11-02T11:05:23.3920401Z Adding assembly reference for System.ComponentModel.Composition, recursively... 2019-11-02T11:05:23.4147682Z Adding assembly reference for System.Net.Http, recursively... 2019-11-02T11:05:23.4584174Z Adding assembly reference for System.Runtime.Serialization, recursively... 2019-11-02T11:05:23.5024670Z Adding assembly reference for System.ServiceModel.Internals, recursively... 2019-11-02T11:05:23.5403709Z Adding assembly reference for System.Web.Services, recursively... 2019-11-02T11:05:23.5666237Z Adding assembly reference for System.Xml.Linq, recursively... 2019-11-02T11:05:23.5689407Z Adding assembly reference for Microsoft.Extensions.Configuration.Binder, recursively... 2019-11-02T11:05:23.5696544Z Adding assembly reference for Microsoft.Extensions.Configuration.CommandLine, recursively... 2019-11-02T11:05:23.5707382Z Adding assembly reference for Microsoft.Extensions.Configuration, recursively... 2019-11-02T11:05:23.5722313Z Adding assembly reference for Microsoft.Extensions.Configuration.EnvironmentVariables, recursively... 2019-11-02T11:05:23.5734555Z Adding assembly reference for Microsoft.Extensions.Configuration.FileExtensions, recursively... 2019-11-02T11:05:23.5762460Z Adding assembly reference for Microsoft.Extensions.Configuration.Json, recursively... 2019-11-02T11:05:23.5788221Z Adding assembly reference for Microsoft.Extensions.Configuration.UserSecrets, recursively... 2019-11-02T11:05:23.5809355Z Adding assembly reference for Microsoft.Extensions.DependencyInjection.Abstractions, recursively... 2019-11-02T11:05:23.5813196Z Adding assembly reference for Microsoft.Extensions.DependencyInjection, recursively... 2019-11-02T11:05:23.5821615Z Adding assembly reference for Microsoft.Extensions.FileProviders.Abstractions, recursively... 2019-11-02T11:05:23.5831788Z Adding assembly reference for Microsoft.Extensions.FileProviders.Physical, recursively... 2019-11-02T11:05:23.5851472Z Adding assembly reference for Microsoft.Extensions.FileSystemGlobbing, recursively... 2019-11-02T11:05:23.5854530Z Adding assembly reference for Microsoft.Extensions.Hosting.Abstractions, recursively... 2019-11-02T11:05:23.5870826Z Adding assembly reference for Microsoft.Extensions.Hosting, recursively... 2019-11-02T11:05:23.5974757Z Adding assembly reference for Microsoft.Extensions.Logging.Abstractions, recursively... 2019-11-02T11:05:23.5977213Z Adding assembly reference for Microsoft.Extensions.Logging.Configuration, recursively... 2019-11-02T11:05:23.6045951Z Adding assembly reference for Microsoft.Extensions.Logging.Console, recursively... 2019-11-02T11:05:23.6074760Z Adding assembly reference for Microsoft.Extensions.Logging.Debug, recursively... 2019-11-02T11:05:23.6092830Z Adding assembly reference for Microsoft.Extensions.Logging, recursively... 2019-11-02T11:05:23.6115211Z Adding assembly reference for Microsoft.Extensions.Logging.EventLog, recursively... 2019-11-02T11:05:23.6281486Z ##[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): 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`. 2019-11-02T11:05:23.6287999Z C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): 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`. [d:\a\1\s\src\Mobile.App\Mobile.App.csproj] 2019-11-02T11:05:23.6290816Z Adding assembly reference for Microsoft.Extensions.Logging.EventSource, recursively... 2019-11-02T11:05:23.6297204Z Adding assembly reference for System.Runtime.CompilerServices.Unsafe, recursively... 2019-11-02T11:05:23.6300859Z Adding assembly reference for Microsoft.Extensions.Options.ConfigurationExtensions, recursively... 2019-11-02T11:05:23.6327692Z Adding assembly reference for Microsoft.Extensions.Options, recursively... 2019-11-02T11:05:23.6341251Z Adding assembly reference for Microsoft.Extensions.Primitives, recursively... 2019-11-02T11:05:23.6352310Z Adding assembly reference for Mono.Android, recursively... 2019-11-02T11:05:23.6375992Z Adding assembly reference for mscorlib, recursively... 2019-11-02T11:05:23.6376370Z Adding assembly reference for System.Buffers, recursively... 2019-11-02T11:05:23.6377216Z Adding assembly reference for System.Core, recursively... 2019-11-02T11:05:23.6382838Z Adding assembly reference for System, recursively... 2019-11-02T11:05:23.6763753Z Adding assembly reference for Mono.Security, recursively... 2019-11-02T11:05:23.6778884Z Adding assembly reference for System.Memory, recursively... 2019-11-02T11:05:23.6780050Z Adding assembly reference for System.Numerics, recursively... 2019-11-02T11:05:23.6783489Z Adding assembly reference for System.Numerics.Vectors, recursively... 2019-11-02T11:05:23.6790224Z Adding assembly reference for System.Runtime, recursively... 2019-11-02T11:05:23.6801234Z Adding assembly reference for System.Text.Encodings.Web, recursively... 2019-11-02T11:05:23.6807668Z Adding assembly reference for System.Text.Json, recursively... 2019-11-02T11:05:23.6830405Z Adding assembly reference for System.Threading.Tasks.Extensions, recursively... 2019-11-02T11:05:23.6854323Z ##[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): 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`. 2019-11-02T11:05:23.6854894Z C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): 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`. [d:\a\1\s\src\Mobile.App\Mobile.App.csproj] 2019-11-02T11:05:23.6855617Z Adding assembly reference for System.Xml, recursively... 2019-11-02T11:05:23.6855833Z Adding assembly reference for Xamarin.Android.Arch.Core.Common, recursively... 2019-11-02T11:05:23.6861087Z Adding assembly reference for Xamarin.Android.Arch.Core.Runtime, recursively... 2019-11-02T11:05:23.6869772Z Adding assembly reference for Xamarin.Android.Arch.Lifecycle.Common, recursively... 2019-11-02T11:05:23.6876790Z Adding assembly reference for Xamarin.Android.Arch.Lifecycle.LiveData.Core, recursively... 2019-11-02T11:05:23.6890836Z Adding assembly reference for Xamarin.Android.Arch.Lifecycle.LiveData, recursively... 2019-11-02T11:05:23.6911376Z Adding assembly reference for Xamarin.Android.Arch.Lifecycle.Runtime, recursively... 2019-11-02T11:05:23.6930393Z Adding assembly reference for Xamarin.Android.Arch.Lifecycle.ViewModel, recursively... 2019-11-02T11:05:23.6937637Z Adding assembly reference for Xamarin.Android.Support.Animated.Vector.Drawable, recursively... 2019-11-02T11:05:23.6960502Z Adding assembly reference for Xamarin.Android.Support.Annotations, recursively... 2019-11-02T11:05:23.6967188Z Adding assembly reference for Xamarin.Android.Support.AsyncLayoutInflater, recursively... 2019-11-02T11:05:23.6974954Z Adding assembly reference for Xamarin.Android.Support.Collections, recursively... 2019-11-02T11:05:23.6982189Z Adding assembly reference for Xamarin.Android.Support.Compat, recursively... 2019-11-02T11:05:23.7026596Z Adding assembly reference for Xamarin.Android.Support.CoordinaterLayout, recursively... 2019-11-02T11:05:23.7052466Z Adding assembly reference for Xamarin.Android.Support.Core.UI, recursively... 2019-11-02T11:05:23.7150757Z Adding assembly reference for Xamarin.Android.Support.Core.Utils, recursively... 2019-11-02T11:05:23.7210197Z Adding assembly reference for Xamarin.Android.Support.CursorAdapter, recursively... 2019-11-02T11:05:23.7219403Z Adding assembly reference for Xamarin.Android.Support.CustomTabs, recursively... 2019-11-02T11:05:23.7229420Z Adding assembly reference for Xamarin.Android.Support.CustomView, recursively... 2019-11-02T11:05:23.7245645Z Adding assembly reference for Xamarin.Android.Support.Design, recursively... 2019-11-02T11:05:23.7342384Z Adding assembly reference for Xamarin.Android.Support.DocumentFile, recursively... 2019-11-02T11:05:23.7350754Z Adding assembly reference for Xamarin.Android.Support.DrawerLayout, recursively... 2019-11-02T11:05:23.7378278Z Adding assembly reference for Xamarin.Android.Support.Fragment, recursively... 2019-11-02T11:05:23.7446060Z Adding assembly reference for Xamarin.Android.Support.Interpolator, recursively... 2019-11-02T11:05:23.7453782Z Adding assembly reference for Xamarin.Android.Support.Loader, recursively... 2019-11-02T11:05:23.7461918Z Adding assembly reference for Xamarin.Android.Support.LocalBroadcastManager, recursively... 2019-11-02T11:05:23.7469339Z Adding assembly reference for Xamarin.Android.Support.Print, recursively... 2019-11-02T11:05:23.7476635Z Adding assembly reference for Xamarin.Android.Support.SlidingPaneLayout, recursively... 2019-11-02T11:05:23.7501553Z Adding assembly reference for Xamarin.Android.Support.SwipeRefreshLayout, recursively... 2019-11-02T11:05:23.7516729Z Adding assembly reference for Xamarin.Android.Support.Transition, recursively... 2019-11-02T11:05:23.7538940Z Adding assembly reference for Xamarin.Android.Support.v7.AppCompat, recursively... 2019-11-02T11:05:23.7595161Z Adding assembly reference for Xamarin.Android.Support.v7.CardView, recursively... 2019-11-02T11:05:23.7602972Z Adding assembly reference for Xamarin.Android.Support.v7.RecyclerView, recursively... 2019-11-02T11:05:23.7629454Z Adding assembly reference for Xamarin.Android.Support.Vector.Drawable, recursively... 2019-11-02T11:05:23.7647164Z Adding assembly reference for Xamarin.Android.Support.VersionedParcelable, recursively... 2019-11-02T11:05:23.7654955Z Adding assembly reference for Xamarin.Android.Support.ViewPager, recursively... 2019-11-02T11:05:23.7723660Z Adding assembly reference for Xamarin.Essentials, recursively... 2019-11-02T11:05:23.8030653Z Done Building Project "d:\a\1\s\src\Mobile.App\Mobile.App.csproj" (default targets) -- FAILED. ```
Local VS info ``` Microsoft Visual Studio Community 2019 Preview Version 16.4.0 Preview 2.0 VisualStudio.16.Preview/16.4.0-pre.2.0+29411.138 Microsoft .NET Framework Version 4.8.03752 Installed Version: Community Visual C++ 2019 00435-60000-00000-AA534 Microsoft Visual C++ 2019 .ignore 1.2.77 A language service that makes it painless to handle all types of .ignore files such as .gitignore, .tfignore, etc. Add New File 3.5.134 The fastest and easiest way to add new files to any project - including files that start with a dot ASP.NET and Web Tools 2019 16.4.284.46185 ASP.NET and Web Tools 2019 ASP.NET Web Frameworks and Tools 2019 16.4.284.46185 For additional information, visit https://www.asp.net/ AssemblyInfo Wizard 1.0 AssemblyInfo Wizard Azure App Service Tools v3.0.0 16.4.284.46185 Azure App Service Tools v3.0.0 C# Tools 3.4.0-beta2-19504-06+154af84a603094b52bd08b3366c4448f7481af52 C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Child Process Debugging Power Tool 1.0 Power tool to add child process debugging to Visual Studio. Code Cleanup On Save 1.0.6 Automatically run one of the Code Clean profiles when saving the document. This ensures your code is always formatted correctly and follows your coding style conventions. CodeMaid 11.0.183 CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, R, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding. Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools. CreateUnitTestBoilerplateCommand Extension 1.0 CreateUnitTestBoilerplateCommand Visual Studio Extension Detailed Info Disable No Source Available Tab 3.0 This small extension will prevent the tool window with title 'No Source Available' from appearing in Visual Studio, and preserve the focus on the currently active tab. Alas, along with brilliant improvements such as IntelliTrace, Visual Studio otherwise displays a tab stating that it cannot find source code where to step into. This is obvious when simply pausing an idle application, therefore it forces the developer to close this window before getting back to the code he wants to modify, which may be a productivity killer. Let's hope this extension will be short-term lived as the Visual Studio development team adds an option to better control this behavior! This extension should work with all locales of Visual Studio. EditorConfig Language Service 1.17.260 Language service for .editorconfig files. EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs. Extensibility Message Bus 1.2.0 (d16-2@8b56e20) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. File Icons 2.7 Adds icons for files that are not recognized by Solution Explorer FormatCommand Extension 1.0 FormatCommand Visual Studio Extension Detailed Info GitHub.VisualStudio 2.10.8.8132 A Visual Studio Extension that brings the GitHub Flow into Visual Studio. GuidGenPackage 1.0 Offers the new GuidGen tool in the VS Tools menu. IntelliCode Extension 1.0 IntelliCode Visual Studio Extension Detailed Info JsonViewer 1.0 JSON viewer Markdown Editor 1.12.236 A full featured Markdown editor with live preview and syntax highlighting. Supports GitHub flavored Markdown. Microsoft Continuous Delivery Tools for Visual Studio 0.4 Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE. Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Microsoft Library Manager 2.0.87+gbb515bf382 Install client-side libraries easily to any web project Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers Microsoft Visual C++ Wizards 1.0 Microsoft Visual C++ Wizards Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container. Microsoft Visual Studio VC Package 1.0 Microsoft Visual Studio VC Package Mono Debugging for Visual Studio 16.5.21 (2604ba1) Support for debugging Mono processes with Visual Studio. NuGet Package Manager 5.4.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/ Open in Visual Studio Code 1.4.46 Adds a menu command that lets you open any solution, project, folder and file in Visual Studio Code. PowerShell Pro Tools for Visual Studio 1.0 A set of tools for developing and debugging PowerShell scripts and modules in Visual Studio. ProjectConfigurationManager 1.9.2171.0 Information about my package ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info Reference Conflict Analyser Extension 1.0 A tool for analysis of the "Could not load file or assembly or one of its dependencies" problem. ReviewsToolWindow Extension 1.0 ReviewsToolWindow Visual Studio Extension Detailed Info Rewrap Extension 1.0 Rewrap Extension Detailed Info Smart Command Line Arguments Extension 2.2.0 A Visual Studio Extension which aims to provide a better UI to manage your command line arguments. For additional information, visit https://github.com/MBulli/SmartCommandlineArgs SQL Server Data Tools 16.0.61910.04130 Microsoft SQL Server Data Tools SubwordNavigation 1.5.0 Provides subword navigation for Visual Studio. Syntax Highlighting Pack 2.8.134 Adds syntax highlighting and snippet support for a wide variety of programming languages such as Clojure, Go, Jade, Lua, Swift, Ruby and many more... TermWindow Extension 1.0 TermWindow Visual Studio Extension Detailed Info TypeScript Tools 16.0.10926.2001 TypeScript Tools for Microsoft Visual Studio Viasfora 4.2.188 Add color to your Visual Studio editor! Visual Basic Tools 3.4.0-beta2-19504-06+154af84a603094b52bd08b3366c4448f7481af52 Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Visual F# Tools 10.4 for F# 4.6 16.4.0-beta.19504.1+e3676d75d501a2df6789ad0f5ebc310bc2cee6b5 Microsoft Visual F# Tools 10.4 for F# 4.6 Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio Visual Studio Container Tools Extensions (Preview) 1.0 View, manage, and diagnose containers within Visual Studio. Visual Studio Spell Check Everywhere VSSpellCheckEverywhere An extension that enables spell checking within any Visual Studio file editor or tool window that uses WPF text boxes. https://GitHub.com/EWSoftware/VSSpellChecker Visual Studio Spell Checker VSSpellChecker An editor extension that checks the spelling of comments, strings, and plain text as you type or interactively with tool windows. https://GitHub.com/EWSoftware/VSSpellChecker Visual Studio Tools for CMake 1.0 Visual Studio Tools for CMake Visual Studio Tools for CMake 1.0 Visual Studio Tools for CMake Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers Visual Studio Tools for Unity 4.4.1.0 Visual Studio Tools for Unity VisualStudio.DeviceLog 1.0 Information about my package VisualStudio.Mac 1.0 Mac Extension for Visual Studio VSColorOutput 2.6.7 Color output for build and debug windows - https://mike-ward.net/vscoloroutput Xamarin 16.4.000.269 (d16-4@9202c30) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android. Xamarin Designer 16.4.0.289 (remotes/origin/d16-4@e3c99110c) Visual Studio extension to enable Xamarin Designer tools in Visual Studio. Xamarin Templates 16.4.15 (51cdaa7) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 10.1.0.1 (d16-4/ee1dfb6) Xamarin.Android Reference Assemblies and MSBuild support. Mono: 5281037 Java.Interop: xamarin/java.interop/d16-4@35b08ba ProGuard: xamarin/proguard/master@905836d SQLite: xamarin/sqlite/3.28.0@46204c4 Xamarin.Android Tools: xamarin/xamarin-android-tools/master@9f4ed4b Xamarin.iOS and Xamarin.Mac SDK 13.8.1.1 (2e360ee) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support. ```

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?

x37v commented 4 years ago

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);
rneeft commented 4 years ago

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 :-(

Eilon commented 4 years ago

@rneeft can you share what error(s) you're getting?

rneeft commented 4 years ago

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.

Eilon commented 4 years ago

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.

rneeft commented 4 years ago

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>
Eilon commented 4 years ago

Thank you, I will take a look in the morning,

Eilon commented 4 years ago

@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?

rneeft commented 4 years ago

@Eilon I tried to move from 3.1.0 to 3.0.0 resulting into fewer errors. The only two left are:

[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1808,2): 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]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1808,2): 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.

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.

rneeft commented 4 years ago

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

yanxiaodi commented 4 years ago

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.

kant2002 commented 4 years ago

@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

VladislavAntonyuk commented 4 years ago

@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

yanxiaodi commented 4 years ago

@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.

DAMcK-TREC commented 4 years ago

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.

kant2002 commented 4 years ago

@DAMcK-TREC Can you try suggestion here? https://github.com/xamarin/xamarin-android/issues/4074#issuecomment-592935384

rneeft commented 4 years ago

I believe the issue is fixed. My test project is building fine on the build server now :)

weitzhandler commented 4 years ago

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.

weitzhandler commented 4 years ago

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.

analogrelay commented 4 years ago

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 :).

Dotnet-GitSync-Bot commented 4 years ago

I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label.

weitzhandler commented 4 years ago

I'm willing to contribute.

rmarinho commented 3 years ago

Any work on this issue? seems is keeping us of using the Host on Android