Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get multiple overlapping config files for multiple solutions in ASP.NET?
    primarykey
    data
    text
    <p>I'm very new to ASP.net, so I'm just figuring this out.</p> <p>First off, I have multiple separate projects that will be hosted on the same server.</p> <p>Second, they must be able to share certain settings (like connection string, configuration options, etc).</p> <p>Third, those shared settings must be configurable for different deployments (test, prod, etc).</p> <p>For example, I have two projects: Project A Project B</p> <p>I have a setting called "Setting1" which should be accessible to both projects.</p> <p>The value for "Setting1" should come from one of these files: "TEST-config.xml" "PROD-config.xml" (There will be more than two config files, but I'll keep it simple for now)</p> <p>And I want to have only a single place to change a single text file, which determines which of the *-config.xml files will be used:</p> <p>"WhichSettingsFile.xml"</p> <p>Here's an example of the file structure:</p> <p>\WhichSettingsFile.xml \TEST-config.xml \PROD-config.xml \Project1\Project1.csproj \Project1\web.config \Project1... (more files) \Project2\Project2.csproj \Project2\web.config \Project2... (more files)</p> <p>So currently, each project has a "web.config" like this:</p> <pre><code>&lt;appSettings file="..\WhichSettingsFile.xml"&gt; ... &lt;/appSettings&gt; </code></pre> <p>Then I have a file "WhichSettingsFile.xml" like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;appSettings&gt; &lt;add key="SettingsFilenamePrefix" value="PROD" /&gt; &lt;/appSettings&gt; </code></pre> <p>And I have code like this:</p> <pre><code>public static string GetSetting(name) { string filename = System.Web.Configuration.WebConfigurationManager.AppSettings["SettingsFilenamePrefix"] + "-config.xml"; // Open filename, parse as XML, get the values I need from it. } </code></pre> <p>This means I can host both projects on Server A, set the WhichSettingsFile.xml to contain "PROD", and all settings will be read from "PROD-config.xml". I can do the same for the test server. And all those values are shared among the separate projects.</p> <p>However, I need to be able to edit these files on the filesystem, and not have them embedded within the dlls / assemblies. When I run the project(s) from visual studio, the built-in asp.net hosting server will deploy the files to something like:</p> <pre><code>C:\Users\[username]\AppData\Local\Temp\6\Temporary ASP.NET Files\lskdjflskj\slkdjfsld\klsjdfwbe </code></pre> <p>But there will be no "WhichSettingsFile.xml" file since it's embedded in the assembly. Furthermore, the "PROD-config.xml" and "TEST-config.xml" files will not be included since they're not really part of the "code", and are not copied.</p> <p>Ideally, I want to have this in the deployment folder:</p> <pre><code>C:\Users\[username]\AppData\Local\Temp\6\Temporary ASP.NET Files\abc123\Project1\(all the compiled files here) C:\Users\[username]\AppData\Local\Temp\6\Temporary ASP.NET Files\abc123\Project2\(all the compiled files here) C:\Users\[username]\AppData\Local\Temp\6\Temporary ASP.NET Files\abc123\WhichSettingsFile.xml C:\Users\[username]\AppData\Local\Temp\6\Temporary ASP.NET Files\abc123\PROD-config.xml C:\Users\[username]\AppData\Local\Temp\6\Temporary ASP.NET Files\abc123\TEST-config.xml </code></pre> <p>But I'm not sure how to do this.</p> <p>So my problems: -The "WhichSettingsFile.xml" is embedded into the assembly. I want this to be a plain text file on the filesystem that is referenced at runtime by the application. I realize I might need to avoid using for this. Is there a better way? -I want to have multiple config files, also as plain text files on the filesystem.</p> <p>I know what I've got is not working, and probably convoluted. But is there a better way to do this? Thanks!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload