2012-10-13 227 views
1

我创建了一个可以使用的新模板。但它只使用一些项目设置Visual Studio模板忽略模板中的一些项目设置

我做了一个项目,工作libSDL喜世界的例子。我导出为一个模板,但模板不保存我的一些设置:(这是节省了“他们,但新项目忽略它们。)

忽略设置:

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> 

回答

0

这可能是因为该项目的系统实际上是除去这些项目,如文件被创建:当您创建一个新的项目时,Visual Studio在后台运行一个向导,它可以影响究竟是什么在新近结束创建的.vcxproj文件。

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

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

请注意,您需要一种方法来确保它只影响您的特定类型的项目; .vcxproj模板文件中的一个标志可以做到这一点。