1. 程式人生 > >Visaul Studio 2017軟體的學習筆記(一):檔案結構

Visaul Studio 2017軟體的學習筆記(一):檔案結構

在使用VS2017建立了一個解決方案並建立專案後,在儲存目錄中會生成一系列檔案,此文對其作用進行解析。

解決方案檔案(.sln 和 .suo)

.sln檔案:

       VisualStudio Solution檔案,與專案同時建立位於解決方案資料夾根目錄,組織解決方案中的專案、專案項和解決方案項。

例:

//版本資訊

Microsoft Visual Studio Solution File, Format Version12.00

# Visual Studio 15

VisualStudioVersion = 15.0.27703.2018

MinimumVisualStudioVersion = 10.0.40219.1

//專案資訊

Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}")= "TEST", "TEST\TEST.vcxproj","{34CF1F5D-E34D-44B9-92AC-2B04826E192E}"

EndProject

//全域性配置

Global

//解決方案配置資訊

   GlobalSection(SolutionConfigurationPlatforms)= preSolution

       Debug|x64= Debug|x64

       Debug|x86= Debug|x86

       Release|x64= Release|x64

       Release|x86= Release|x86

   EndGlobalSection

//專案配置性資訊

   GlobalSection(ProjectConfigurationPlatforms)= postSolution

       {34CF1F5D-E34D-44B9-92AC-2B04826E192E}.Debug|x64.ActiveCfg= Debug|x64

       {34CF1F5D-E34D-44B9-92AC-2B04826E192E}.Debug|x64.Build.0= Debug|x64

       {34CF1F5D-E34D-44B9-92AC-2B04826E192E}.Debug|x86.ActiveCfg= Debug|Win32

       {34CF1F5D-E34D-44B9-92AC-2B04826E192E}.Debug|x86.Build.0= Debug|Win32

       {34CF1F5D-E34D-44B9-92AC-2B04826E192E}.Release|x64.ActiveCfg= Release|x64

       {34CF1F5D-E34D-44B9-92AC-2B04826E192E}.Release|x64.Build.0= Release|x64

       {34CF1F5D-E34D-44B9-92AC-2B04826E192E}.Release|x86.ActiveCfg= Release|Win32

       {34CF1F5D-E34D-44B9-92AC-2B04826E192E}.Release|x86.Build.0= Release|Win32

   EndGlobalSection

//解決方案屬性

   GlobalSection(SolutionProperties)= preSolution

       HideSolutionNode= FALSE

   EndGlobalSection

//擴充套件配置

   GlobalSection(ExtensibilityGlobals)= postSolution

       SolutionGuid= {1EE3581B-D885-4795-87C5-E3A8B6B86E8A}

   EndGlobalSection

EndGlobal

.suo檔案:(暫未遇見)

       SolutionUser Option檔案,儲存程式設計師對 Visual Studio 所做的使用者級自定義,即處理過專案的每個使用者儲存設定、首選項和配置資訊,如斷點。

配置檔案(.vcxproj和.vcxproj.user)

.vcxproj

       用於儲存MSBuild配置,包含.props和.targets檔案的配置,以及需要匯入的XML文件。

例:

//版本資訊

<?xml version="1.0"encoding="utf-8"?>

<Project DefaultTargets="Build"ToolsVersion="15.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>

   <ProjectConfiguration Include="Debug|x64">

     <Configuration>Debug</Configuration>

     <Platform>x64</Platform>

   </ProjectConfiguration>

   <ProjectConfiguration Include="Release|x64">

     <Configuration>Release</Configuration>

     <Platform>x64</Platform>

   </ProjectConfiguration>

 </ItemGroup>

//全域性資訊

 <PropertyGroup Label="Globals">

   <VCProjectVersion>15.0</VCProjectVersion>

   <ProjectGuid>{34CF1F5D-E34D-44B9-92AC-2B04826E192E}</ProjectGuid>

   <Keyword>Win32Proj</Keyword>

   <RootNamespace>TEST</RootNamespace>

<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>

 </PropertyGroup>

//預設編譯器配置匯入

  <ImportProject="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"Label="Configuration">

   <ConfigurationType>Application</ConfigurationType>

   <UseDebugLibraries>true</UseDebugLibraries>

   <PlatformToolset>v141</PlatformToolset>

   <CharacterSet>Unicode</CharacterSet>

 </PropertyGroup>

 <PropertyGroupCondition="'$(Configuration)|$(Platform)'=='Release|Win32'"Label="Configuration">

   <ConfigurationType>Application</ConfigurationType>

   <UseDebugLibraries>false</UseDebugLibraries>

   <PlatformToolset>v141</PlatformToolset>

   <WholeProgramOptimization>true</WholeProgramOptimization>

   <CharacterSet>Unicode</CharacterSet>

 </PropertyGroup>

 <PropertyGroupCondition="'$(Configuration)|$(Platform)'=='Debug|x64'"Label="Configuration">

   <ConfigurationType>Application</ConfigurationType>

   <UseDebugLibraries>true</UseDebugLibraries>

   <PlatformToolset>v141</PlatformToolset>

   <CharacterSet>Unicode</CharacterSet>

 </PropertyGroup>

 <PropertyGroupCondition="'$(Configuration)|$(Platform)'=='Release|x64'"Label="Configuration">

   <ConfigurationType>Application</ConfigurationType>

   <UseDebugLibraries>false</UseDebugLibraries>

   <PlatformToolset>v141</PlatformToolset>

   <WholeProgramOptimization>true</WholeProgramOptimization>

   <CharacterSet>Unicode</CharacterSet>

 </PropertyGroup>

//編譯器關於C++的預設配置匯入

  <ImportProject="$(VCTargetsPath)\Microsoft.Cpp.props" />

 <ImportGroup Label="ExtensionSettings">

 </ImportGroup>

 <ImportGroup Label="Shared">

 </ImportGroup>

 <ImportGroup Label="PropertySheets"Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">

   <ImportProject="$(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'">

   <ImportProject="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"Label="LocalAppDataPlatform" />

  </ImportGroup>

 <ImportGroup Label="PropertySheets"Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">

   <ImportProject="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"Label="LocalAppDataPlatform" />

 </ImportGroup>

 <ImportGroup Label="PropertySheets"Condition="'$(Configuration)|$(Platform)'=='Release|x64'">

   <ImportProject="$(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>

 <PropertyGroupCondition="'$(Configuration)|$(Platform)'=='Debug|x64'">

   <LinkIncremental>true</LinkIncremental>

 </PropertyGroup>

 <PropertyGroupCondition="'$(Configuration)|$(Platform)'=='Release|Win32'">

   <LinkIncremental>false</LinkIncremental>

 </PropertyGroup>

 <PropertyGroupCondition="'$(Configuration)|$(Platform)'=='Release|x64'">

   <LinkIncremental>false</LinkIncremental>

 </PropertyGroup>

 <ItemDefinitionGroupCondition="'$(Configuration)|$(Platform)'=='Debug|Win32'">

   <ClCompile>

     <PrecompiledHeader>Use</PrecompiledHeader>

     <WarningLevel>Level3</WarningLevel>

     <Optimization>Disabled</Optimization>

     <SDLCheck>true</SDLCheck>

     <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>

     <ConformanceMode>true</ConformanceMode>

   </ClCompile>

   <Link>

     <SubSystem>Console</SubSystem>

      <GenerateDebugInformation>true</GenerateDebugInformation>

   </Link>

 </ItemDefinitionGroup>

 <ItemDefinitionGroupCondition="'$(Configuration)|$(Platform)'=='Debug|x64'">

   <ClCompile>

     <PrecompiledHeader>Use</PrecompiledHeader>

     <WarningLevel>Level3</WarningLevel>

     <Optimization>Disabled</Optimization>

     <SDLCheck>true</SDLCheck>

     <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>

     <ConformanceMode>true</ConformanceMode>

   </ClCompile>

   <Link>

     <SubSystem>Console</SubSystem>

     <GenerateDebugInformation>true</GenerateDebugInformation>

   </Link>

 </ItemDefinitionGroup>

 <ItemDefinitionGroupCondition="'$(Configuration)|$(Platform)'=='Release|Win32'">

   <ClCompile>

     <PrecompiledHeader>Use</PrecompiledHeader>

     <WarningLevel>Level3</WarningLevel>

     <Optimization>MaxSpeed</Optimization>

     <FunctionLevelLinking>true</FunctionLevelLinking>

     <IntrinsicFunctions>true</IntrinsicFunctions>

     <SDLCheck>true</SDLCheck>

     <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>

     <ConformanceMode>true</ConformanceMode>

   </ClCompile>

   <Link>

     <SubSystem>Console</SubSystem>

     <EnableCOMDATFolding>true</EnableCOMDATFolding>

     <OptimizeReferences>true</OptimizeReferences>

     <GenerateDebugInformation>true</GenerateDebugInformation>

   </Link>

 </ItemDefinitionGroup>

 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">

   <ClCompile>

     <PrecompiledHeader>Use</PrecompiledHeader>

     <WarningLevel>Level3</WarningLevel>

     <Optimization>MaxSpeed</Optimization>

     <FunctionLevelLinking>true</FunctionLevelLinking>

     <IntrinsicFunctions>true</IntrinsicFunctions>

     <SDLCheck>true</SDLCheck>

     <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>

     <ConformanceMode>true</ConformanceMode>

   </ClCompile>

   <Link>

     <SubSystem>Console</SubSystem>

     <EnableCOMDATFolding>true</EnableCOMDATFolding>

     <OptimizeReferences>true</OptimizeReferences>

     <GenerateDebugInformation>true</GenerateDebugInformation>

   </Link>

 </ItemDefinitionGroup>

//包含檔案資訊

 <ItemGroup>

   <ClInclude Include="stdafx.h" />

   <ClInclude Include="targetver.h" />

 </ItemGroup>

 <ItemGroup>

   <ClCompile Include="stdafx.cpp">

     <PrecompiledHeaderCondition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>

     <PrecompiledHeaderCondition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>

     <PrecompiledHeaderCondition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>

     <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>

   </ClCompile>

   <ClCompile Include="TEST.cpp" />

 </ItemGroup>

  <ImportProject="$(VCTargetsPath)\Microsoft.Cpp.targets" />

 <ImportGroup Label="ExtensionTargets">

  </ImportGroup>

</Project>

.vcxproj.user

儲存使用者配置檔案。

例:

//未作配置修改

<?xml version="1.0"encoding="utf-8"?>

<Project ToolsVersion="15.0"xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

 <PropertyGroup />

</Project>

專案檔案組織結構(.vcxproj.filters)

       儲存專案檔案虛擬目錄的組織結構。

例:

//版本資訊

<?xml version="1.0"encoding="utf-8"?>

<Project ToolsVersion="4.0"xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

//資料夾目錄

 <ItemGroup>

   <Filter Include="原始檔">

     <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>

     <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>

   </Filter>

   <Filter Include="標頭檔案">

     <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>

     <Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>

   </Filter>

   <Filter Include="資原始檔">

     <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>

     <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>

   </Filter>

 </ItemGroup>

//專案包含的檔案

 <ItemGroup>

   <ClInclude Include="stdafx.h">

     <Filter>標頭檔案</Filter>

   </ClInclude>

   <ClInclude Include="targetver.h">

     <Filter>標頭檔案</Filter>

   </ClInclude>

 </ItemGroup>

 <ItemGroup>

   <ClCompile Include="stdafx.cpp">

     <Filter>原始檔</Filter>

   </ClCompile>

   <ClCompile Include="TEST.cpp">

     <Filter>原始檔</Filter>

   </ClCompile>

 </ItemGroup>

</Project>

預設自動生成的檔案(.h和.cpp)

targetver.h

定義可用的最高版本的Windows 平臺。如果要為以前的 Windows 平臺生成應用程式,要包括 WinSDKVer.h,並將 _WIN32_WINNT 巨集設定為要支援的平臺,然後再包括 SDKDDKVer.h。

例:

#pragma once

#include <SDKDDKVer.h>

stadafx.h

StandardApplication Fram Extend,標準系統包含檔案的包含檔案,或是經常使用但不常更改的特定於專案的包含檔案。這就使得使用者在開發中不必在每一個cpp檔案中都煩瑣的include標頭檔案了,而且,維護起來也方便。

例:

#pragmaonce

#include"targetver.h"

#include<stdio.h>

#include<tchar.h>

stadafx.cpp

       伴隨stadafx.h一起生成,只包含 #include"stdafx.h" 語句,在編譯過程中第一個被編譯並儲存在stdafx.pch的檔案中,後續的cpp檔案編譯呼叫時便直接訪問此檔案,而不再分析Windows include 檔案,此方法有效地提高了編譯效率。