前提・実現したいこと
F#でWPFのアプリケーションを作りたいです。
発生している問題・エラーメッセージ
空のウィンドウを開くことを期待しましたが、ウィンドウは開かず、プログラムがすぐ終了してしまいます。
リビルドを実行すると、以下のメッセージが残っていて、mainが空だと言われます。
実行時、例外などは発生していないようです。
リビルドを開始しました... 1>------ すべてのリビルド開始: プロジェクト:MyApp, 構成: Debug Any CPU ------ D:\Workspace\repos\MyApp\MyApp\MyApp.fsproj を復元しました (415 ms)。 1>D:\Workspace\repos\MyApp\MyApp\obj\Debug\net472\MyApp.AssemblyInfo.fs(17,5): warning FS0988: プログラムのメイン モジュールが空です。実行しても何も処理されません 1>MyApp-> D:\Workspace\repos\MyApp\MyApp\bin\Debug\net472\MyApp.exe 1>プロジェクト "MyApp.fsproj" のビルドが終了しました。 ========== すべてリビルド: 1 正常終了、0 失敗、0 スキップ ==========
ソースコード
fsharp
1open System 2open System.Windows 3open System.Windows.Controls 4open System.Windows.Markup 5 6[<STAThread>] 7[<EntryPoint>] 8let main argv = 9 let mainWindow = Application.LoadComponent( 10 new System.Uri("/MyApp;component/MainWindow.xaml", UriKind.Relative)) :?> Window 11 12 let application = new Application() 13 application.Run(mainWindow)
fsharp
1// <auto-generated> 2// Generated by the FSharp WriteCodeFragment class. 3// </auto-generated> 4namespace FSharp 5 6open System 7open System.Reflection 8 9 10[<assembly: System.Reflection.AssemblyCompanyAttribute("MyApp")>] 11[<assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")>] 12[<assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")>] 13[<assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")>] 14[<assembly: System.Reflection.AssemblyProductAttribute("MyApp")>] 15[<assembly: System.Reflection.AssemblyTitleAttribute("MyApp")>] 16[<assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")>] 17do() 18
参考
インストールしてあるVisual Studio 2019のスタート画面からはF# Empty Windows Appのテンプレートが無いため、以下のサイトの手順に従ってコンソールアプリのテンプレートをもとにプロジェクトを作成しています。
Creating a WPF application in F#
補足情報(FW/ツールのバージョンなど)
Visual Studioとインストールされたコンポーネントの情報です
Microsoft Visual Studio Community 2019 Version 16.11.0 VisualStudio.16.Release/16.11.0+31605.320 Microsoft .NET Framework Version 4.8.04084 インストールされているバージョン:Community Visual C++ 2019 00435-60000-00000-AA646 Microsoft Visual C++ 2019 ASP.NET and Web Tools 2019 16.11.75.64347 ASP.NET and Web Tools 2019 Azure App Service Tools v3.0.0 16.11.75.64347 Azure App Service Tools v3.0.0 Boost.Test のテスト アダプター 1.0 Boost.Test 向けに作成された単体テストを含む、Visual Studio のテスト ツールを有効にします。拡張機能のインストール ディレクトリに、使用条件およびサード パーティからの通知が含まれています。 C# ツール 3.11.0-4.21403.6+ae1fff344d46976624e68ae17164e0607ab68b10 IDE で使用する C# コンポーネント。プロジェクトの種類や設定に応じて、異なるバージョンのコンパイラを使用できます。 Common Azure Tools 1.10 Azure Mobile Services および Microsoft Azure Tools で使用する共通サービスを提供します。 IntelliCode 拡張機能 1.0 IntelliCode Visual Studio 拡張機能の詳細情報 Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers Microsoft Visual C++ ウィザード 1.0 Microsoft Visual C++ ウィザード Microsoft Visual Studio VC パッケージ 1.0 Microsoft Visual Studio VC パッケージ NuGet パッケージ マネージャー 5.11.0 Visual Studio 内の NuGet パッケージ マネージャー。NuGet の詳細については、https://docs.nuget.org/ にアクセスしてください ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info Test Adapter for Google Test 1.0 Google Test 向けに作成された単体テストを含む、Visual Studio のテスト ツールを有効にします。拡張機能のインストール ディレクトリに、使用条件およびサード パーティからの通知が含まれています。 TypeScript Tools 16.0.30526.2002 TypeScript Tools for Microsoft Visual Studio Visual Basic ツール 3.11.0-4.21403.6+ae1fff344d46976624e68ae17164e0607ab68b10 IDE で使用する Visual Basic コンポーネント。プロジェクトの種類や設定に応じて、異なるバージョンのコンパイラを使用できます。 Visual F# Tools 16.11.0-beta.21322.6+488cc578cafcd261d90d748d8aaa7b8b091232dc Microsoft Visual F# Tools Visual Studio Code デバッグ アダプターのホスト パッケージ 1.0 Visual Studio Code デバッグ アダプターを Visual Studio でホストするための相互運用レイヤー Visual Studio Tools for CMake 1.0 Visual Studio Tools for CMake Visual Studio Tools for Unity 4.11.3.0 Visual Studio Tools for Unity
普通に F# のテンプレートを使えばいいのに、なぜこれを参考にしたんですか?
レスポンスありがとうございます。
使っているVisual Studioのスタート画面からはF# Windows Appのテンプレートが見つからなかったためです。
一応vsixファイルを見つけましたが、こちらもインストール済みのVisual Studioのバージョンでは利用できませんでした。
https://marketplace.visualstudio.com/items?itemName=DanielMohl.FEmptyWindowsAppWPF
古いバージョンのVisual Studio(2015?)をインストールしてそちらで開発を行った方がベターでしょうか?
VS2019 で F# で WPF ですよね?
あるはずだと思うんですが。
「Visual Studio Code デバッグ アダプターのホスト パッケージ」という謎のメッセージがありますね。
> VS2019 で F# で WPF ですよね?
はい、そうです。
> あるはずだと思うんですが。
なるほど。そうなると必要なコンポーネントをダウンロードできていないなど、Visual Studioのインストールの時点で何か問題があるのかもしれませんね……
有益な情報ありがとうございます。
すみません。私が何かと間違えていたようです。
気になって調べてみると、テンプレートはないようです。
https://stackoverflow.com/questions/63329605/template-for-f-and-wpf-visual-studio-2019-community
[WPFでF#も使いたい!](https://zenn.dev/flipflap/articles/use-wpf-with-fsharp
これはどうですか?こちらの手元では窓が出ました。
@TN8001 ありがとうございます。先ほどそちらのページも見つけました。そちらも試してみようと思います。
@TN8001 ありがとうございます。そちらのページの手順で解決しました。
同じ内容を回答として投稿していただければ、そちらで解決という処理にさせていただこうと思います。
回答1件
あなたの回答
tips
プレビュー