【问题标题】:MSAL.NET+Xamarin.Forms: build error when adding the latest Microsoft.Identity.ClientMSAL.NET+Xamarin.Forms:添加最新的 Microsoft.Identity.Client 时生成错误
【发布时间】:2019-11-08 06:47:00
【问题描述】:

我正在尝试将 MSAL.NET 添加到一个空的 Xamarin.Forms 项目,但我无法编译它。在 netstandard 2.0 项目(Xamarin.Forms 项目)上添加对 Microsoft.Identity.Client nuget 包的引用后,我无法构建解决方案:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1962,2): error XA2002: Can not resolve reference: `Microsoft.Identity.Client`, referenced by `Grm.Assistencias`. 
Please add a NuGet package or assembly reference for `Microsoft.Identity.Client`, or remove the reference to `Grm.Assistencias`.

查看解决方案资源管理器,我没有看到任何参考警告或错误。

这是 netstandard 项目的 csproj 文件:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <ProduceReferenceAssembly>true</ProduceReferenceAssembly>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DebugType>pdbonly</DebugType>
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Autofac" Version="4.9.2" />
    <PackageReference Include="Microsoft.Identity.Client" Version="4.0.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
    <PackageReference Include="Xamarin.Forms" Version="4.0.0.497661" />
    <PackageReference Include="Xamarin.Essentials" Version="1.1.0" />
  </ItemGroup>
</Project>

这是 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>{A7B816FB-9BBD-4CBD-B666-F45754F35326}</ProjectGuid>
    <ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <TemplateGuid>{c9e5eea5-ca05-42a1-839b-61506e0a37df}</TemplateGuid>
    <OutputType>Library</OutputType>
    <RootNamespace>Grm.Assistencias.Droid</RootNamespace>
    <AssemblyName>Grm.Assistencias.Android</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>
    <AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
    <NuGetPackageImportStamp>
    </NuGetPackageImportStamp>
  </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>
    <AotAssemblies>false</AotAssemblies>
    <EnableLLVM>false</EnableLLVM>
    <BundleAssemblies>false</BundleAssemblies>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>portable</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release</OutputPath>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <AndroidManagedSymbols>true</AndroidManagedSymbols>
    <AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Mono.Android" />
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Xml" />
    <Reference Include="System.Numerics" />
    <Reference Include="System.Numerics.Vectors" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Identity.Client">
      <Version>4.0.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Forms" Version="4.0.0.497661" />
    <PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.1" />
    <PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="28.0.0.1" />
    <PackageReference Include="Xamarin.Android.Support.v4" Version="28.0.0.1" />
    <PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="28.0.0.1" />
    <PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="28.0.0.1" />
    <PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.1" />
    <PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="28.0.0.1" />
    <PackageReference Include="Xamarin.Essentials" Version="1.1.0" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="MainActivity.cs" />
    <Compile Include="Resources\Resource.designer.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="Resources\AboutResources.txt" />
    <None Include="Assets\AboutAssets.txt" />
    <None Include="Properties\AndroidManifest.xml" />
  </ItemGroup>
  <ItemGroup>
    <AndroidResource Include="Resources\layout\Tabbar.axml" />
    <AndroidResource Include="Resources\layout\Toolbar.axml" />
    <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\icon.png" />
    <AndroidResource Include="Resources\mipmap-hdpi\launcher_foreground.png" />
    <AndroidResource Include="Resources\mipmap-mdpi\icon.png" />
    <AndroidResource Include="Resources\mipmap-mdpi\launcher_foreground.png" />
    <AndroidResource Include="Resources\mipmap-xhdpi\icon.png" />
    <AndroidResource Include="Resources\mipmap-xhdpi\launcher_foreground.png" />
    <AndroidResource Include="Resources\mipmap-xxhdpi\icon.png" />
    <AndroidResource Include="Resources\mipmap-xxhdpi\launcher_foreground.png" />
    <AndroidResource Include="Resources\mipmap-xxxhdpi\icon.png" />
    <AndroidResource Include="Resources\mipmap-xxxhdpi\launcher_foreground.png" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="Resources\drawable-hdpi\" />
    <Folder Include="Resources\drawable-xhdpi\" />
    <Folder Include="Resources\drawable-xxhdpi\" />
    <Folder Include="Resources\drawable-xxxhdpi\" />
    <Folder Include="Resources\drawable\" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Grm.Assistencias\Grm.Assistencias.csproj">
      <Project>{039DA92D-24ED-44B5-8DCF-4BB2C6D935C7}</Project>
      <Name>Grm.Assistencias</Name>
    </ProjectReference>
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>

关于这里发生了什么的任何线索?

谢谢。

【问题讨论】:

  • 你能提供你的简单项目吗?我在空白表单项目中添加了Microsoft.Identity.Client,但它在 Android 模拟器上运行良好。
  • 你好。我在 github 上添加了一个问题:github.com/AzureAD/microsoft-authentication-library-for-dotnet/…(有代码和构建的输出)。它似乎与 VS 2017 到 2019 迁移有关,虽然我还没有格式化我的机器......如果有什么方法可以在不格式化机器的情况下解决这个问题,请告诉我......
  • 已经在github上关闭了。我无法为您提供更多建议,因为我无法在我这边重现此问题。如果您想获得更多帮助,请尝试在此处打开支持票:support.microsoft.com/en-us/supportforbusiness/…
  • 好吧,我的机器肯定出了什么问题...格式化它现在可以工作了...

标签: android xamarin.forms msbuild msal


【解决方案1】:

我只是尝试按照您的复制步骤进行操作,但我无法做到。看起来错误来自 Grm.Assistencias.csproj - 这也是引用 MSAL(直接还是间接?)。

如果在 Grm.Assistencias 的依赖关系的传递闭包中存在 MSAL,您可能希望直接依赖于 MSAL。

【讨论】:

  • 你好。 Grm,Assistencias.csproj 是包含 Xamarin.Forms 使用的 xaml 页面的网络标准项目。是的,我在这两个项目中都添加了对 Microsoft.Identity.Client nuget 包的引用(即,我在 net 标准和 android csproj 文件中添加了对 msal.net nuget 项目的引用)。顺便说一句,我试过关注这个示例github.com/Azure-Samples/active-directory-xamarin-native-v2,但可能错过了一些东西......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
相关资源
最近更新 更多