![](/img/trans.png)
[英]How to get user input during windows installer for WinForms application?
[英]How to create Winforms Installer application with CMake
我想知道如何使用CMake為C#Winforms應用程序創建.msi安裝程序或等效文件? 我已經搜索並找到了CPack,但是沒有提及它是否能夠安裝Winforms應用程序。 我也有需要包含在我的.exe中的dll。
如果您有使用CMake配置的現有C#項目,則邏輯途徑是使用CPack創建Winforms安裝程序。 CPack可以定位多個生成器(NSIS,WiX等)之一,但這是使用WiX的一個簡單示例(帶有庫和可執行文件)。
cmake_minimum_required (VERSION 3.13)
# Create a C# project.
project(MyProj LANGUAGES CSharp)
# Include CMake utilities for CSharp, for WinForm and WPF application support.
include(CSharpUtilities)
# Group our library and executable source files.
set(DLL_SRCS
MyDLL/MyClass.cs
MyDLL/Properties/AssemblyInfo.cs
)
set(EXE_SRCS
App.config
Form1.cs
Form1.Designer.cs
Form1.resx
Program.cs
Properties/AssemblyInfo.cs
Properties/Resources.Designer.cs
Properties/Resources.resx
Properties/Settings.Designer.cs
Properties/Settings.settings
)
# Create the DLL library.
add_library(MyLibrary SHARED ${DLL_SRCS})
# Create the Winforms executable.
add_executable(MyWinFormApp ${EXE_SRCS})
# Set the .NET Framework version.
set_property(TARGET MyLibrary PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1")
set_property(TARGET MyWinFormApp PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1")
# Set the executable to be 32-bit.
set_property(TARGET MyWinFormApp PROPERTY WIN32_EXECUTABLE TRUE)
# Set the C# language version (defaults to 3.0).
set(CMAKE_CSharp_FLAGS "/langversion:latest")
# Set the source file properties for Windows Forms use.
csharp_set_windows_forms_properties(
${DLL_SRCS}
${EXE_SRCS}
)
# If necessary, link in other library dependencies that were built locally in this source tree.
target_link_libraries(MyWinFormApp MyLibrary)
# Add in the .NET reference libraries.
set_property(TARGET MyLibrary PROPERTY VS_DOTNET_REFERENCES
"Microsoft.CSharp"
"System"
"System.Core"
"System.Data"
"System.Drawing"
"System.Windows.Forms"
)
set_property(TARGET MyWinFormApp PROPERTY VS_DOTNET_REFERENCES
"Microsoft.CSharp"
"System"
"System.Core"
"System.Data"
"System.Drawing"
"System.Windows.Forms"
)
# Set the installation configuration, putting the targets in the 'bin' folder.
install(TARGETS MyLibrary
CONFIGURATIONS Release
RUNTIME DESTINATION bin
)
install(TARGETS MyWinFormApp
CONFIGURATIONS Release
RUNTIME DESTINATION bin
)
# Tell CPack to use the WIX generator.
set(CPACK_GENERATOR WIX)
include(CPack)
# Set the CPACK and WIX variables here.
set(CPACK_PACKAGE_NAME "MyWinFormApp")
set(CPACK_PACKAGE_VERSION "1.0.0")
set(CPACK_WIX_PROGRAM_MENU_FOLDER "My Winform Application")
當CMake生成Visual Studio解決方案時,CMake預定義項目將出現在解決方案資源管理器中,名為PACKAGE ; 進行構建以創建安裝程序。
CPack WiX 生成器提供了許多變量,允許您使用安裝位置,安裝程序名稱,GUID,安裝程序圖標和品牌徽標,許可證,“開始”菜單和桌面快捷方式等自定義安裝程序。 我強烈建議您查看CPack和CPack-WiX鏈接,以查看哪些自定義選項適合您的項目。
請注意,對於WiX的安裝,我必須確保在計算機上也已安裝並啟用了.NET 3.5.1。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.