必威体育Betway必威体育官网
当前位置:首页 > IT技术

MSBuild //Visual Studio生成系统

时间:2019-10-01 23:14:33来源:IT技术作者:seo实验室小编阅读:86次「手机版」
 

msbuild

以下部分引用自https://www.cnblogs.com/shanyou/p/3452938.html

MSbuild是Visual Studio的生成系统,可以简单的理解为Visual Studio的编译器,它能解释构造文件,执行构造动作,生成工程文件

MSBuild所解释的项目文件已XML架构定义,依靠XML文件来指示生成引擎生成哪些内容以及如何生成这些内容。

简单列一下MSBuild XML架构元素https://msdn.microsoft.com/zh-cn/library/5dy88c2e(v=vs.120).aspx元素

Element child Elements Attributes
Choose Element(MSBuild)

Otherwise

When

--
Import Element(MSBuild) --

Condition

Project

ImportGroup Element(MSBuild) Import Condition
Item Element(MSBuild) ItemMetaData

Condition

Exclude

Include

Remove

ItemDefinitionGroup Element(MSBuild) Item Condition
ItemGroup Element(MSBuild) Item Condition
ItemMetadata Element(MSBuild) Item Condition
OnERROR --

Condition

ExecuteTargets

OtherWise Element(MSBuild)

Choose

ItemGroup

PropertyGroup

--
Output Element(MSBuild) --

Condition

ItemName

PropertyName

Taskparameter

Parameter Element(MSBuild) --

Output

ParameterType

required

ParameterGroup Element(MSBuild)

Parameter --
Project Element(MSBuild)

Choose

Import

ItemGroup

PorjectExtensions

PropertyGroup

Target

UsingTask

DefaultTargets

InitialTargets

ToolsVersion

TreatAslocalProperty

xmlns

ProjectExtensions Element(MSBuild) -- --
Property Element(MSBuild) --

Condition

PropertyGroup Element(MSBuild) Property Condition
Target Element(MSBuild)

OnError

Task

AfterTargets

BeforeTargets

Condition

DependsOnTargets

Inputs

KeepDuplicateOutputs

Name

Outputs

Returns

Task Element(MSBuild) Output

Condition

ContinueOnError

Parameter

TaskBody Element(MSBuild) Data Evaluate
UsingTask Element(MSBuild)

ParameterGroup

TaksBody

AssemblyFile

AssemblyName

Condition

TaskFactory

TaskName

When Element(MSBuild)

Choose

ItemGroup

PropertyGroup

Condition
  • Project元素

这是每一个项目文件的最外层元素,它表示了一个项目的范围,不可或缺。

注意它的子元素Targets和属性DefaultTargets,有些人把它的DefaultTargets看成目标,把Targets看成任务,我觉得这样子理解很到位。

  • Property元素

在项目中一些经常访问的信息,以name/value的形式存放之后,可以以$(PropertyName)的形式访问。name即元素名,value即元素值

可以用$()引用自定义的属性,也可以引用系统的环境变量,以及MSBuild保留属性

属性除了可以在项目文件中声明是赋值外,在MSBuild命令行也允许设置属性的值

MSBuild condition.xml /p:Platform=x64//以这种方式修改的属性值会覆盖xml里面的属性值
  • Item元素

在整个项目文件中你需要提供一些可被引用的输入性资源信息,比如源代码文件、引用的程序集名称、需要嵌入的图标资源等。我们可以引用自定义的一些元数据(以键/值对的形式存储),还可以调用一些隐式存在的元数据,即不用声明即可使用,可以看看https://docs.microsoft.com/zh-cn/previous-versions/dotnet/netframework-4.0/ms164313(v=vs.100)

  • Target元素

Target表示一个需要完成的虚拟的任务单元。每个Project可以包括一个或多个Target,从而完成一系列定制的任务。

http://www.cnblogs.com/linianhui/archive/2012/09/01/2666104.html

这里面谈到了它的任务是原子操作(简单理解,某个操作不会被其它任务打断),但是xml格式的项目文件没有这个处理能力,所以这些任务都是映射到.NET类的,这些类处理操作中的逻辑。具体来说都是实现ITask接口的类,这位笔者用的C#,我想这当然可以采用c++,但是我没有去证实,时间太紧了。

  • Import元素

用来导入可重用的项目文件,这位笔者把它看成是占位元素,是很有道理的,就是实际在执行的时候,会被立即替换,注意和Item元素的区分,他们的作用是不同的

  • MSBuild会用到一些特殊字符http://www.cnblogs.com/linianhui/archive/2012/09/01/2666104.html

%:引用元数据//%(元数据名)

$:引用属性//$(属性名)

@:引用项(item)

':条件或其它表达式

;:列表分隔符

?:文件名通配符

*:文件名通配符

以及XML的保留字符:<、>、&、"、'

MSBuild条件:condition属性以及一些bool表达式

<!--如果configuration为空(''),则其值为Debug-->
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>

有了对以上一些顶级元素的初步了解,我们来看一个实际的.vcxprohttps://blog.csdn.net/huhaoxuan2010/article/details/76797588

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.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="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{2B4C8F7A-A827-41E5-B80A-8EE6C0D3AF03}</ProjectGuid>
    <Keyword>Win32Proj</keyword>
    <RootNamespace>test</RootNamespace>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>APPlication</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v120</PlatformToolset>
    <CharacterSet>unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v120</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v120</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</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 Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
    <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>
  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
    <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)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
    <IncludePath>E:\osvr-build-ok\boost_1_62_0;$(IncludePath)</IncludePath>
    <LibraryPath>E:\osvr-build-ok\boost_1_62_0\lib64-msvc-12.0;$(LibraryPath)</LibraryPath>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LinkIncremental>false</LinkIncremental>
    <IncludePath>E:\osvr-build-ok\boost_1_62_0;$(IncludePath)</IncludePath>
    <LibraryPath>E:\osvr-build-ok\boost_1_62_0\lib64-msvc-12.0;$(LibraryPath)</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>disabled</Optimization>
      <PreprocessorDefinitions>WIN32;_DEBUG;_console;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <SDLCheck>true</SDLCheck>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <generatedebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <SDLCheck>true</SDLCheck>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <SDLCheck>true</SDLCheck>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <Optimizereferences>true</OptimizeReferences>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <SDLCheck>true</SDLCheck>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <Text Include="ReadMe.txt" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="stdafx.h" />
    <ClInclude Include="targetver.h" />
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="stdafx.cpp">
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
    </ClCompile>
    <ClCompile Include="test.cpp" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>

相关阅读

Android Studio开发JNI示例

JNI和NDK介绍 JNI(Java Native Interface),是方便Java调用C、C++等Native代码所封装的一层接口,相当于一座桥梁。通过JNI可以操作一些

Visual Studio 2015版本下载地址和对应关系

Visual Studio 2015版本下载地址 http://download.microsoft.com/download/B/8/9/B898E46E-CBAE-4045-A8E2-2D33DD36F3C4/vs2015.

windows下搭建android studio开发环境

一. 系统环境 32位windows只能管理4G内存,导致android开发工具运行时内存占用率达到90%以上。所以还是安装64位windows吧,使用8G以

android studio 创建项目失败原因Failed to create

1.先把问题贴出来 看看有没有小伙伴一样的大意说的原因就是创建目录失败,就百度查一查 发现 没有配对的问题目录结构都是空的,其实

苏宁上线Surface studio 2,28英寸超大屏幕29888 元起

众所周知,微软的产品一直在国际上备受赞誉,在Windows系统安装到全球每一台电脑中的同时,微软的硬件包括电脑,平板等也因为极高的品质

分享到:

栏目导航

推荐阅读

热门阅读