C# Debug和Release编译生成相同目录不同文件名方法

1.打开配置文件

使用Notepad++或其他文件编辑器打开ConsoleApplication1.csproj文件

2.编译配置

修改原有配置文件为:

<PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{F6E0FC4C-9FE2-4C45-B608-85DB32039AC3}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Test</RootNamespace>
    <AssemblyName Condition="'$(Configuration)'=='Debug'">MyApp_Debug</AssemblyName>
    <AssemblyName Condition="'$(Configuration)'=='Release'">MyApp_Release</AssemblyName>
    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>

生成不同文件名XML配置项:

<AssemblyName Condition="'$(Configuration)'=='Debug'">MyApp_Debug</AssemblyName>
<AssemblyName Condition="'$(Configuration)'=='Release'">MyApp_Release</AssemblyName>

设置目录XML配置项:

<OutputPath>bin\</OutputPath>

3.参考

https://stackoverflow.com/questions/1093338/vs2008-outputting-a-different-file-name-for-debug-release-configurations

猜你喜欢

转载自blog.csdn.net/sdhongjun/article/details/80449838
今日推荐