编译 uwp-community-toolkit dll 问题

compiling uwp-community-toolkit dll issue

一位贡献者在他们自己的分支中对 "Toolkit.win32.ui.controls" 进行了一些更新。我在我的项目中下载、编译并引用了生成的 dll。我在对象浏览器中看到 API 变化(见附图);但是,编译器似乎看不到这些更改,因为每当我尝试使用额外的 APIs.

时都会出错

分支机构:https://github.com/rjmurillo/UWPCommunityToolkit/tree/WebView/NavigateWithHttpMessage

他所做的改变: https://github.com/Microsoft/WindowsCommunityToolkit/pull/2195

错误发生的地方:

 Uri url = webView.BuildLocalStreamUri("MyTag", "/Minesweeper/default.html");

错误:

Severity    Code    Description Project File    Line    Suppression State
Error   CS1061  'WebView' does not contain a definition for 'BuildLocalStreamUri' and no extension method 'BuildLocalStreamUri' accepting a first argument of type 'WebView' could be found (are you missing a using directive or an assembly reference?)   Test.WPF    C:\Users\Adam\Desktop\Test.WPF\MainWindow.xaml.cs   29  Active

它几乎就好像它仍在使用原始的、未修改的参考版本,因为它确实识别 "WebView"。

XAML:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:SparkStore.WPF"
        xmlns:winforms="clr-namespace:Microsoft.Toolkit.Win32.UI.Controls.WinForms;assembly=Microsoft.Toolkit.Win32.UI.Controls"
        xmlns:WPF="clr-namespace:Microsoft.Toolkit.Win32.UI.Controls.WPF;assembly=Microsoft.Toolkit.Win32.UI.Controls" x:Class="Test.WPF.MainWindow"
        mc:Ignorable="d"
        Title="Test" Height="450" Width="800">
    <Grid>
        <WPF:WebView x:Name="webView" Margin="0"/>
    </Grid>
</Window>

项目文件:

[![<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{525B29B6-0498-46D2-A1E9-EDBBFA4FA34D}</ProjectGuid>
    <OutputType>WinExe</OutputType>
    <RootNamespace>Test.WPF</RootNamespace>
    <AssemblyName>Test.WPF</AssemblyName>
    <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <WarningLevel>4</WarningLevel>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <TargetFrameworkProfile />
    <PublishUrl>publish\</PublishUrl>
    <Install>true</Install>
    <InstallFrom>Disk</InstallFrom>
    <UpdateEnabled>false</UpdateEnabled>
    <UpdateMode>Foreground</UpdateMode>
    <UpdateInterval>7</UpdateInterval>
    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
    <UpdatePeriodically>false</UpdatePeriodically>
    <UpdateRequired>false</UpdateRequired>
    <MapFileExtensions>true</MapFileExtensions>
    <ApplicationRevision>0</ApplicationRevision>
    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
    <IsWebBootstrapper>false</IsWebBootstrapper>
    <UseApplicationTrust>false</UseApplicationTrust>
    <BootstrapperEnabled>true</BootstrapperEnabled>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Microsoft.Toolkit.Win32.UI.Controls">
      <HintPath>..\UWPCommunityToolkit\Microsoft.Toolkit.Win32\Microsoft.Toolkit.Win32.UI.Controls\bin\AnyCPU\Release\net462\Microsoft.Toolkit.Win32.UI.Controls.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="System.Design" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Xml" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xaml">
      <RequiredTargetFramework>4.0</RequiredTargetFramework>
    </Reference>
    <Reference Include="WindowsBase" />
    <Reference Include="PresentationCore" />
    <Reference Include="PresentationFramework" />
  </ItemGroup>
  <ItemGroup>
    <ApplicationDefinition Include="App.xaml">
      <Generator>MSBuild:Compile</Generator>
      <SubType>Designer</SubType>
    </ApplicationDefinition>
    <Page Include="MainWindow.xaml">
      <Generator>MSBuild:Compile</Generator>
      <SubType>Designer</SubType>
    </Page>
    <Compile Include="App.xaml.cs">
      <DependentUpon>App.xaml</DependentUpon>
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="MainWindow.xaml.cs">
      <DependentUpon>MainWindow.xaml</DependentUpon>
      <SubType>Code</SubType>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Properties\AssemblyInfo.cs">
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="Properties\Resources.Designer.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
    <Compile Include="Properties\Settings.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Settings.settings</DependentUpon>
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
    </Compile>
    <EmbeddedResource Include="Properties\Resources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
    </EmbeddedResource>
    <None Include="Properties\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
    </None>
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <ItemGroup>
    <BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
      <Visible>False</Visible>
      <ProductName>Microsoft .NET Framework 4.6.1 %28x86 and x64%29</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
  </ItemGroup>
  <ItemGroup>
    <Resource Include="Readme.txt" />
  </ItemGroup>
  <Import Project="..\Test\Test.projitems" Label="Shared" />
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>][1]][1]

WebView 的 Windows 社区工具包版本的目标之一是提供 WinRT 和 .NET 概念之间的分离,并提供从性质和局限性的抽象,从而在 Win32 和 UWP 应用程序之间架起一座桥梁,因此在初始版本中省略了一些 API。通过在没有任何抽象的情况下公开 BuildLocalStreamUri(String, String),return 值向托管 Web 视图的 Win32WebViewHost UWP 应用程序(例如 ms-local-stream://microsoft.win32webviewhost_cw5n1h2txyewy_54657374/foo.htm)提供相对 URI,而不是 Windows 表单或WPF 应用程序本身,这可能会造成混淆。

提到的分支确实为 BuildLocalStreamUri 提供支持,但是,它旨在在 NavigateToLocalStreamUri(Uri, IUriToStreamResolver)NavigateToLocal(String) 的上下文中使用以提供该抽象。使用这些方法中的任何一种都将在内部调用 BuildLocalStreamUri 以规范化 URI,并调用 IUriToStreamResolver 的实例将资产转换为 System.IO.Stream.