Quantcast
Channel: C#タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9703

VSCode で .net 5.0 で WinForms で CefSharp を使用する手順

$
0
0

CefSharp は AnyCPU で使えないらしいので、x64 前提。
同じ方法で、.net core 3 とかでも使用出来る。

以下はVS2019での作業

① Visual Studio 2019 で、
 [Windows フォーム アプリケーション(.Net Framework)]
 を作成する。

② ソリューション > プロパティ > 構成プロパティ > 構成マネージャ
 で、プラットフォーム を [Any CPU] から [x64] に変更。

③ nuget で、CefSharp.Common と、CefSharp.WinForms を get してビルドする。
 (bin フォルダに、アプリの exe 等と並んで、CefSharp 関連の dll 等がたくさん配置される。これを後で使う。)


以下は.net core SDK と VSCode での作業

④ dotnet new winforms -o TestApplication
 でプロジェクト作成(ここでの名前はとりあえず TestApplication にした。)

⑤ 上記プロジェクトを VS Code で開き、とりあえず実行する。
 すると、以下のフォルダに exe とかが作られる。
 ..\TestApplicationd\bin\Debug\netcoreapp5.0

⑥ 作業③で勝手に作成された CefSharp 関連の dll 等を、作業⑤で作成された、\netcoreapp5.0 フォルダにコピペする。

⑦ VSCode で、作業④で作成されたプロジェクトを開き、TestApplication.csproj を編集する。
 (Platforms を x64 に指定し、ItemGroup として、CefSharp 関連 dll への参照を追加する)
 ※ItemGroup で dll へのパスを設定することで、ソースコードで using 可能になる。

TestApplicatoin.csproj
<ProjectSdk="Microsoft.NET.Sdk.WindowsDesktop"><PropertyGroup><OutputType>WinExe</OutputType><TargetFramework>netcoreapp5.0</TargetFramework><UseWindowsForms>true</UseWindowsForms><Platforms>AnyCPU;x64</Platforms></PropertyGroup><ItemGroup><ReferenceInclude="CefSharp"><HintPath>.\bin\Debug\netcoreapp5.0\CefSharp.dll</HintPath></Reference></ItemGroup><ItemGroup><ReferenceInclude="CefSharp.Core"><HintPath>.\bin\Debug\netcoreapp5.0\CefSharp.Core.dll</HintPath></Reference></ItemGroup><ItemGroup><ReferenceInclude="CefSharp.WinForms"><HintPath>.\bin\Debug\netcoreapp5.0\CefSharp.WinForms.dll</HintPath></Reference></ItemGroup></Project>

⑧ フォームにコントロールとして追加し、実行。
無題.jpg


Viewing all articles
Browse latest Browse all 9703

Trending Articles