抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

CMake构建C#项目并使用DLL

项目路径

Windows cmd下使用tree /f即可生成文件路径

.
│ CMakeLists.txt
│ Main.cs
│ p4api.net.dll
│ p4bridge.dll
cmake_minimum_required(VERSION 3.23)
project(P4Test CSharp)
set_property(GLOBAL PROPERTY VS_STARTUP_PROJECT P4Test)
set(CMAKE_VS_EFFECTIVE_PLATFORMS x64)

set(SOURCES
${CMAKE_SOURCE_DIR}/Main.cs
)

add_executable(P4Test ${SOURCES})

set_property(TARGET P4Test PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.7.2")
set_property(TARGET P4Test PROPERTY VS_DOTNET_REFERENCE_P4API "${CMAKE_SOURCE_DIR}/p4api.net.dll")

add_custom_command(
TARGET P4Test
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/p4api.net.dll
$<TARGET_FILE_DIR:P4Test>
)
add_custom_command(
TARGET P4Test
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/p4bridge.dll
$<TARGET_FILE_DIR:P4Test>
)
using Perforce.P4;

namespace P4DoNetApi
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello world");
}
}
}

评论