【问题标题】:Visual Studio template ignores some project settings that are in templateVisual Studio 模板忽略模板中的一些项目设置
【发布时间】:2012-10-13 22:40:03
【问题描述】:

我创建了一个可以使用的新模板。但是它只使用一些项目设置

我使用libSDL hi world 示例创建了一个项目。我导出为模板,但模板没有保存我的一些设置:(它“保存”它们,但新项目会忽略它们。)

忽略的设置:

include header folders:
    for .h files
    for .lib files
linker args: SDLmain.lib SDL.lib
windows subsystem: /SUBSYSTEM:WINDOWS

这是保存的/template/sdl/sdl.vcxproj 文件,设置实际上出现在其中,但它们被忽略了

<?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>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{8DDA73A6-86DD-4B03-BA9B-54BE878B648C}</ProjectGuid>
    <RootNamespace>$safeprojectname$</RootNamespace>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v110</PlatformToolset>
    <CharacterSet>MultiByte</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v110</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>MultiByte</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)'=='Release|Win32'">
    <IncludePath>C:\cpp_libs\SDL-1.2.15\include;$(IncludePath)</IncludePath>
    <ReferencePath>C:\cpp_libs\SDL-1.2.15\lib\x86;$(ReferencePath)</ReferencePath>
    <LibraryPath>C:\cpp_libs\SDL-1.2.15\lib\x86;$(LibraryPath)</LibraryPath>
    <SourcePath>C:\cpp_libs\SDL-1.2.15\include;$(SourcePath)</SourcePath>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
    </ClCompile>
    <Link>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
    </ClCompile>
    <Link>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <AdditionalDependencies>SDLmain.lib;SDL.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <SubSystem>Windows</SubSystem>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClCompile Include="Source.cpp" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>

【问题讨论】:

    标签: visual-studio-2012 visual-studio-templates


    【解决方案1】:

    在创建文件时,项目系统实际上可能正在删除这些项目:当您创建新项目时,Visual Studio 会在后台运行一个向导,这可能会影响新创建的 @987654322 中的实际结果@ 文件。

    这些向导特定于项目类型,因此您实际上可以通过.vstemplate 文件中的&lt;WizardExtension&gt; 元素supply your own。当然,通过覆盖项目创建逻辑,您可能会失去某些功能/行为(除非有一种方法可以继承原始向导的基本程序集)。

    另外,我过去使用的一个解决方案是创建一个处理SolutionEvents_ProjectAdded 方法(在DTE.SolutionEvents 中)的VSPackage。每当创建新项目或将新项目添加到解决方案时都会调用此方法,因此您可以根据需要使用它来设置项目。

    请注意,您需要一种方法来确保它只影响您特定类型的项目; .vcxproj 模板文件中的标志会执行此操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-05
      • 1970-01-01
      • 2016-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-01
      • 2017-02-09
      相关资源
      最近更新 更多