Visual Studio:" App.config"的自定义名称;在项目中,而不是外部项目?

时间:2015-10-22 10:59:07

标签: c# xml visual-studio configuration

正如标题所示,我想重命名" App.config"在项目内部使用除默认名称之外的其他名称。 我知道在你构建解决方案之后它会被重命名为项目名称,但是在构建之前我无法在项目中给它一个不同的名称...

实施例: 我的解决方案名称是" Test123",我希望将配置文件命名为" Test123.config"在项目建成之前。我不在乎它之后的名字。

好。我已经重做了所有内容,我的app.config文件在我的项目中具有以下结构:

<?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
            <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
                <section name="Codex.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
            </sectionGroup>
        </configSections>
<userSettings>
    <Codex.Properties.Settings>
        <setting name="Location" serializeAs="String">
            <value>0, 0</value>
        </setting>
    </Codex.Properties.Settings>
</userSettings>

我将其重命名为&#34; Codex.config&#34;在项目内部,我调试应用程序我在运行时遇到此错误(当我尝试从&#34; X&#34;按钮关闭应用程序时(当执行&#34; Properties.Settings时,我也得到它)。 Default.Save();&#34):

A first chance exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll

1 个答案:

答案 0 :(得分:0)

您可以编辑预构建事件,以便VS复制文件并重命名

xcopy "$(ProjectDir)YourCustomNameInTheProject.config" "$(TargetDir)$(AssemblyName).exe.config*"