0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WPFからUWPのAPIを使う手順

Last updated at Posted at 2019-11-06

TL;DR

  • WPFからUWPのAPIを呼び出すための一番簡単な方法を記載します。
  • UwpDesktopを使用する方法もありますが、最新のOSでは動かないことがあったため、手作業で行う方法を記載します。

リソース

環境

  • Windows 10 1903 (OS ビルド 18362.418)
  • Visual Studio 2019 16.3.7

手順

(1) Packageフォルダを削除します。

もし、試行錯誤等を行ったPackageフォルダがソリューションファイルと同じフォルダにある場合は削除します。

(2) ソリューションのNugetパッケージの管理を開きます。

image.png

(3) 対象のプロジェクトに「UwpDesktop」がある場合にはアンインストールします。

image.png

(4) プロジェクトをアンロードしてcsprojファイルを編集し、以下のUwpDesktop関連のブロックを削除します。

  <ItemGroup>
    <Analyzer Include="..\packages\UwpDesktop.10.0.14393.3\analyzers\dotnet\UwpDesktopAnalyzer.dll" />
  </ItemGroup>

(5) 以下の2つのファイルを参照します。

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.18362.0\Windows.winmd

誤った例

例えば、以下の場所を参照すると、コンパイルは成功しても、API使用箇所でファイルまたはアセンブリ 'System.Runtime.WindowsRuntime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'、またはその依存関係の 1 つが読み込めませんでしたといったエラーが表示されます。

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5.1\System.Runtime.WindowsRuntime.dll
C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Facade\Windows.winmd
0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?