Add default build configuration to Visual Studio

你离开我真会死。 提交于 2019-12-07 08:10:54

问题


My team and I are using VS2012 for a number of projects, and have developed a workflow with our QA and UAT group that involves 5 environments: Local, Development Staging, Testing, Preproduction, and Production. We've found ourselves having to create Local/Dev/Test/Preprod/Prod build configuration for every project and solution, and remove the debug and release configurations.

Is there any way to have VS create these environments by default on new projects instead of the debug/release configurations?

EDIT: I've not been able to find any Global option for this, as it seems the build configurations are all in the individual project folders.

What I've done is find some of my most common projects and modified the project templates thusly:

  • Modify the .csproj file and replace PropertyGroups with the following:
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Local|AnyCPU' ">
        <DebugSymbols>true</DebugSymbols>
        <DebugType>full</DebugType>
        <Optimize>false</Optimize>
        <OutputPath>bin\</OutputPath>
        <DefineConstants>DEBUG;TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
    </PropertyGroup>
    <-- SNIP -->
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Prod|AnyCPU' ">
        <DebugType>pdbonly</DebugType>
        <Optimize>true</Optimize>
        <OutputPath>bin\</OutputPath>
        <DefineConstants>TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
    </PropertyGroup>
  • Add my appropriate Web.Config transform directives:
    <Content Include="Web.config" />
    <Content Include="Web.Local.config">
        <DependentUpon>Web.config</DependentUpon>
    </Content>
    <Content Include="Web.Dev.config">
        <DependentUpon>Web.config</DependentUpon>
    </Content>
    <Content Include="Web.Test.config">
        <DependentUpon>Web.config</DependentUpon>
    </Content>
    <Content Include="Web.Preprod.config">
        <DependentUpon>Web.config</DependentUpon>
    </Content>
    <Content Include="Web.Prod.config">
        <DependentUpon>Web.config</DependentUpon>
    </Content>
  • Modified my .vstemplate file and replaced the Web.Debug and Web.Release config entries as such:
    <ProjectItem ReplaceParameters="true" TargetFileName="Web.config">WebApiWeb.config</ProjectItem>
    <ProjectItem ReplaceParameters="true" TargetFileName="Web.Local.config">Web.Local.config</ProjectItem>
    <ProjectItem ReplaceParameters="true" TargetFileName="Web.Dev.config">Web.Dev.config</ProjectItem>
    <ProjectItem ReplaceParameters="true" TargetFileName="Web.Test.config">Web.Test.config</ProjectItem>
    <ProjectItem ReplaceParameters="true" TargetFileName="Web.Preprod.config">Web.Preprod.config</ProjectItem>
    <ProjectItem ReplaceParameters="true" TargetFileName="Web.Prod.config">Web.Prod.config</ProjectItem>
  • I copied and renamed Web.Debug.config to Web.Local.config, Web.Dev.config, and Web.Test.config and Web.Release.config to Web.Preprod.config and Web.Prod.config.

When I create the new projects, all of my desired environments are there, and debug is gone! However, Release is still there, including the web.Release.Config file, which I deleted. Any idea where this extraneous config file/build configuration may be coming from?


回答1:


Yes, create a custom project template. If this does not suffice, you can even create a custom project type, which is a bit more involved, however.



来源:https://stackoverflow.com/questions/17371404/add-default-build-configuration-to-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!