了解编译Ansi C90的MsBuild工程文件

问题描述 投票:0回答:1

下面主要想通过msbuild编译

#include <stdio.h>

int main (int argc, char *argv[])
{
    char Buffer[2000];
    printf("TEST");
    gets(Buffer);
}

批处理文件调用 msbuild:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild main.vcxproj
pause

msbuild工程文件如下

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <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>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ItemGroup>
    <ClCompile Include="main.c" />
  </ItemGroup>
</Project>

到目前为止整个设置都有效,但我需要找到一个好的资源来帮助我了解更多关于 msproject 文件的信息。 我想学习多种东西。我怎样才能:

  • 摆脱“导入”选项并自己定义导入的零件
  • 使用命令行参数编译一组文件...( %param%.c %param%TEST.c ,...)
  • 使用项目文件立即启动程序(%param%Test.exe)
  • 编译多个目标,...发布,调试等
  • 编译后复制:Subproject/release/%param%.obj -> c: ccurateVersion\%param%.obj
  • 重建前清洁
msbuild projects-and-solutions c89 ansi-c
1个回答
1
投票

有一本很棒的书,里面有很多示例代码可以完成您所说的一切。

深入了解 Microsoft® 构建引擎:使用 MSBuild 和 Team Foundation Build

这里是如何调用 clean,然后调用构建目标,并让它编译调试和发布配置。 C:\Windows\Microsoft.NET\Framework 4.0.30319\msbuild main.vcxproj /t:clean;build /p:Configuration=Debug;Release /p:platform=Win32

复制任务:

<ItemGroup>
    <MySourceFiles Include="c:\MySourceTree\**\*.*"/>
</ItemGroup>

<Target Name="CopyFiles">
    <Copy
        SourceFiles="@(MySourceFiles)"
        DestinationFiles="@(MySourceFiles->'c:\MyDestinationTree\%(RecursiveDir)%    (Filename)%(Extension)')"
 />

此链接可能会帮助您解决其他一些问题。

演练:使用 MSBuild 创建 Visual C++ 项目

© www.soinside.com 2019 - 2024. All rights reserved.