EXE项目和DLL项目远程调试、Props设置说明

通用宏设置

  • exe项目根据平台配置设置输出路径;

  • dll项目根据平台配置设置输出路径,dll文件lib文件分别输出到自己的路径;

  • 中间文件根据平台配置项目设置输出路径;

  • 设置远程调试命令远程工作目录远程服务器目录部署目录等;

Common.props,exe项目和dll项目添加。

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Label="UserMacros">
    <AppOutDir>$(SolutionDir)_Bin\$(PlatformShortName)$(Configuration)</AppOutDir>
    <DllOutDir>$(SolutionDir)_Dll\$(PlatformShortName)$(Configuration)\bin</DllOutDir>
    <IntOutDir>$(SolutionDir)_Tmp\$(ProjectName)\$(PlatformShortName)$(Configuration)</IntOutDir>
    <IncOutDir>$(SolutionDir)_Dll\inc</IncOutDir>
    <LibOutDir>$(SolutionDir)_Dll\$(PlatformShortName)$(Configuration)\lib</LibOutDir>
    <RemoteDbgCmd>C:\Bin\GlDevDemo\GlDevDemod.exe</RemoteDbgCmd>
    <RemoteDbgWorkDir>C:\Bin\GlDevDemo</RemoteDbgWorkDir>
    <RemoteServer>VMLINK001</RemoteServer>
    <DeployDir>\\$(RemoteServer)\Bin\GlDevDemo</DeployDir>
  </PropertyGroup>
  <PropertyGroup>
    <!-- exe、dll等文件输出的目录          -->
    <OutDir Condition="'$(ConfigurationType)'=='Application'">$(AppOutDir)\</OutDir>
    <OutDir Condition="'$(ConfigurationType)'=='DynamicLibrary'">$(DllOutDir)\</OutDir>
    <!-- obj等中间文件输出的目录           -->
    <IntDir>$(IntOutDir)\</IntDir>
    <!-- 头文件目录                       -->
    <IncludePath>$(IncOutDir);$(IncludePath)</IncludePath>
    <!-- 库文件目录                       -->
    <LibraryPath>$(LibOutDir);$(LibraryPath)</LibraryPath>
    <!-- 输出文件的文件名                  -->
    <TargetName Condition="'$(Configuration)'=='Debug'">$(ProjectName)d</TargetName>
    <TargetName Condition="'$(Configuration)'=='Release'">$(ProjectName)</TargetName>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <Link>
      <!-- 让lib在debug和release情况下名称相同,方便导入 -->
      <ImportLibrary Condition="'$(ConfigurationType)'=='DynamicLibrary'">$(LibOutDir)\$(ProjectName).lib</ImportLibrary>
    </Link>
  </ItemDefinitionGroup>
</Project>

DLL项目宏设置

  • 利用生成后事件复制头文件dll文件pdb文件到指定文件夹;

PostBuild.props,dll项目添加。

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemDefinitionGroup>
    <PostBuildEvent>
      <Command>@echo off
setlocal enabledelayedexpansion 

rem 创建本项目的头文件路径
set dir="$(IncOutDir)"
if not exist %dir% (
  md %dir%
)

rem 创建输出路径,确保路径存在
set dir="$(AppOutDir)"
if not exist %dir% (
  md %dir%
)

rem 源文件
set src[0]="$(ProjectDir)GlXdma.h"
set src[1]="$(TargetPath)"
set src[2]="$(TargetDir)$(TargetName).pdb"

rem 目标文件
set dst[0]="$(IncOutDir)\GlXdma.h"
set dst[1]="$(AppOutDir)\$(TargetFileName)"
set dst[2]="$(AppOutDir)\$(TargetName).pdb"

rem 复制文件
for /L %%n in (0, 1, 2) do (
  echo copy !src[%%n]! to !dst[%%n]!
  copy      !src[%%n]!    !dst[%%n]!
)
</Command>
    </PostBuildEvent>
  </ItemDefinitionGroup>
</Project>

添加属性

  • 项目的属性管理器中添加好上面的Props文件

远程调试设置

  • 项目->调试,选中远程 Windows 调试器,按下图设置好

  • 项目属性->部署

参考

在 Visual Studio 中远程调试 C++ 项目

  • 另用secpol.msc打开本地安全策略,添加账户作为服务登陆权限,以启用Visual Studio 2019 Remote Debugger服务:
    经测试桌面程序不能用服务调试。

posted on 2022-12-17 10:39  OctoberKey  阅读(100)  评论(0编辑  收藏  举报

导航