c++ - 带有 vcxproj 的 msbuild 输出目录不同于 MSVS 构建

标签 c++ dll visual-studio-2013 msbuild vcxproj

我是 MSVS 的新手,似乎需要编写一个可执行程序和一个 DLL。我有 MSVS 2013 项目,其中包含我尝试使用 msbuild 构建的 DLL 的 vcxproj 文件。

从 MSVS 运行构建时,它会创建类似 ${ROOT_PROJECT_FOLDER}/${PROJECT_NAME}/Release 的文件夹,其中存储构建日志。它还使用 exp、lib 和 pdb 文件创建 DLL 本身。它们位于 ${ROOT_PROJECT_FOLDER}/Release 中。

但是,当我尝试运行时

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe cryptoApiLib\cryptoApiLib.vcxproj /t:Build /p:PreferredToolArchitecture=x86 /p:Platform=Win32 /p:PlatformToolset=v120_xp /p:Configuration=Release /p:TargetFrameworkVersion=v3.5

从根项目文件夹开始,DLL 位于 ${ROOT_PROJECT_FOLDER}/${PROJECT_NAME}/Release。我需要在 ${ROOT_PROJECT_FOLDER}/Release 中创建它。不知道我到底做错了什么。

这是 vcxproj 文件的一部分:

...
<ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{ECFFC1B0-5155-41C7-8C03-DD94EB590E3A}</ProjectGuid>
    <Keyword>Win32Proj</Keyword>
    <RootNamespace>cryptoApiLib</RootNamespace>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v120_xp</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v120</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  ...

这就是我使用 vcxproj 运行 msbuild 的方式:

 C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe cryptoApiLib\cryptoApiLib.vcxproj /t:Build /p:PreferredToolArchitecture=x86 /p:Platform=Win32 /p:PlatformToolset=v120_xp /p:Configuration=Release /p:TargetFrameworkVersion=v3.5 

有什么建议吗?

最佳答案

不知道为什么 /p:OutDir 参数在第一次尝试时对我不起作用。浏览了项目属性并提出了将其作为 msbuild 参数传递的想法。终于让它工作了。现在我的构建批处理文件如下所示:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe cryptoApiLib\cryptoApiLib.vcxproj /t:Rebuild /p:PreferredToolArchitecture=x86 /p:Platform=Win32 /p:PlatformToolset=v120_xp /p:Configuration=Release /p:TargetFrameworkVersion=v3.5 /p:OutDir=%~dp0\Release

希望对其他人有所帮助。谢谢。

关于c++ - 带有 vcxproj 的 msbuild 输出目录不同于 MSVS 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30860094/

相关文章:

c++ - 如果我需要从容器中随机获取一个项目,我应该选择哪个 STL 容器

c++ - Delphi:从外部 DLL (C++) 调用函数后发生访问冲突

c++ - 如何调试 Excel 对 COM 服务器的加载?

c# - 如何更新到数据库

python - nng支付nng pub/sub。客户端未收到任何消息

c++ - AtmelATAES132 Mac一代

c++ - 在使用Qt 5.9.4的Fedora上,我无法同时记录和播放音频

c# - 如何防止dll被加载到其他应用程序中

asp.net-mvc - ASP.NET MVC5/IIS Express 无法调试 - 代码未运行

c++ - MSB4018 "ResolveComReference"任务意外失败