简体   繁体   English

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

[英]Visual Studio: Custom name for “App.config” in project, not outside project?

As the title suggests, I'd like to rename "App.config" inside the project to a different name other than the default one. 顾名思义,我想将项目内的“ App.config”重命名为默认名称以外的其他名称。 I know it gets renamed to the project name after you build the solution, but it bugs me that I can't give it a diferent name inside the project, before I build... 我知道您在构建解决方案后将其重命名为项目名称,但这使我感到困惑,因为在构建之前,我无法在项目内部给它一个不同的名称。

Example: My solution name is "Test123", and I'd like to have the config file named "Test123.config" before the project gets built. 示例:我的解决方案名称是“ Test123”,在构建项目之前,我想将配置文件命名为“ Test123.config”。 I don't care what name it has afterwards. 我不在乎它的名字叫什么。

Okay. 好的。 I've redone everything and I have the app.config file with the following structure in my project: 我已经重做了所有事情,并且在我的项目中有以下结构的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>

After I rename it to "Codex.config" inside the project, and I debug the application I get this error when running (and I also get it when I try to close the application from the "X" button (when doing "Properties.Settings.Default.Save();"): 将其重命名为项目内的“ Codex.config”,并调试应用程序后,在运行时会出现此错误(当我尝试通过“ X”按钮关闭应用程序(执行“属性”时,也会遇到此错误)。 Settings.Default.Save();“):

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 项目外部的WCF app.config服务名称 - WCF app.config Service Name outside of Project 如何在Web项目解决方案visual studio中的单独项目中部署app.config - How to deploy app.config in separate project within a web project solution visual studio Visual Studio 2012测试项目正在从machine.config而非从app.config加载配置设置 - visual studio 2012 test project is loading configuration settings from machine.config but not from app.config App.config 不使用 Visual Studio 之外的值 - App.config Not using Values outside of Visual Studio 如何将app.config添加到Visual Studio 2012 Web Express lib项目? - How to add app.config to Visual Studio 2012 Web Express lib project? 如何在不同的解决方案之间共享相同的 Visual Studio 项目? 不同的 app.config 和 settings.settings - How to share same Visual Studio project between different solutions? Different app.config and setttings.settings Visual Studio / MSBuild将引用类库的app.config复制为* .dll.config到当前项目的bin文件夹 - Visual Studio/MSBuild copy referenced class library's app.config as *.dll.config to bin folder of current project Visual Studio 2008自动化测试项目可以读取诸如app.config之类的配置文件? (C#.NET) - A Visual Studio 2008 automated tests project can read a configuration file like app.config? (C# .NET) 在 Visual Studio 中重建 app.config? - Rebuilding app.config in visual studio? 将app.config文件复制到项目外部的文件夹后,尝试读取设置时返回null - After copying app.config file a folder outside the project, when trying to read settings return null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM