I have multiple console applications each one has an app.config file, this way is a little impractical because if I need to change the email server configuration I have to make the change in all the app.config files, I want to create a single configuration file or something similar so I can have all the configuration in a single place.
which is the best way to achive this? I was thinking in a xml file.
I have one way of doing it. First, you change your app.config file so that the appSettings is pulled from a separate file. Replace the entire appSettings section with the following :
<appSettings file="myappsettings.config"/>
Then you need to create the myappSettings.config file. You can create this new file anywhere. I keep it in the root of the Solution folder. Include everything that was in the appSettings section, including the opening and closing tags in the file.
Then, in each project, add the new myappsettings.config file as an existing item. It will link the new config file to your project and copy it to the project output at compile time.
When you need to change settings, just change the appSettings in myappsettings.config.
Related
I need to read the settings file (appsettings.json) from another project in my solution. When I use:
Directory.GetCurrentDirectory()
From within the current project, I get the following path:
{projectRootFolder}\bin\Debug\netcoreapp3.0\
My question is: How can I get to the exact same folder in another project in the same solution? Or is there a better way to access the settings file from another project within the current solution?
If I understand the problem correctly there are two misconceptions:
It has little sense to access output directory of an another project as the structure has sense in compile time only. You will not have the same structure in run-time once the application is "published".
The Directory.GetCurrentDirectory() returns the current working directory. It is just a coincidence to be set to project output directory by Visual Studio. It can be totally different directory.
It is not clear to me what exactly you are trying to achieve. I recommend using the configuration system provided by .net core to access the configuration and add that other appsettings.json as another configuration provider.
If you really need to open the settings file then the project with the settings file (A) should mark the file as "Copy to Output Directory" and the project to open the file (B) should reference the project A. So the settings file will be copied to output of the project A too.
What you're attempting to do is not possible. There's no inherent way for ASP.NET Core to know where a totally different app running in a totally different process is located.
If you need to access appsettings.json from another project, then you would need to include it as a linked file in your project, and set it to copy to output. Then, you're accessing it actually from your project (which is all you can do), but the file itself is shared.
However, this is almost always a bad idea, and usually a sign that you're doing something wrong. If you truly do need to share the settings, then what you should be doing is putting them in a distributed config provider like Azure Key Vault or similar, where both projects can independently access the settings from a common store.
I have a vb.net application and in the startup folder I have an XML config file. I want to read the settings from this file, not from the user/app/ folder. Is there any way that i will define the application to read configuration from this file?
You really made a poor description of your problem;
You don't want to read a configuration file, you want to read an XML file. There are literally thousands of examples for that.
How to read an XML File
Is it possible to externalize rest-messages.properties in SDR?
I tried to move it to ./config folder, for example, but it didn't work.
The rest-messages.properties (used to add custom details to your ALPS descriptions) goes to the same location where you would put custom application-*.properties or messages-*.properties file.
For instance, for a Spring Boot project the .properties file are located in the src/main/resources/ directory.
You can also set custom config locations for your .properties file.
Edit after the OP's comment: However, I tried using a custom rest-messages.properties outside of the project .jar (as I usually do with my application.properties), and it does not seem to work.
I have a problem using Intellij Idea.
I am absolutely unable to load text file as InputStream - it doesnt matter where do I put the file (main/java, main/resources...) it just can't find the file - in Eclipse everything works just fine.
I tried setings->compiler->resource patterns and added ?*.txt but that doesn't seem to work either.
Any help is appreciated.
If you load it as a File, make sure that Working Directory is properly set in IDEA Run/Debug Configuration, since it's the default directory where Java will look for a file when you try to access it like new File("file.txt"). Working directory should be set to the directory of your project containing .txt files.
If you load files as a classpath resource, then they should reside somewhere under Source root and will be copied to the classpath according to Settings | Compiler | Resource Patterns.
If you can't get it working, upload your project somewhere including IDEA project files so that we can point to your mistake.
Look at the image, notice that the txt files are in the project root, and not the source folders (in blue).
If you open the Project Structure dialog, and click on Modules and select your module - are the correct folders marked as Source Folders on the sources tab?
Link for how to get to Project Structure dialog
Also, if you print out the absolute path of that file you are trying to read, is that anywhere near where you expect it to be?
An easy way to figure out the same would be to try creating a file in the same fashion and see where it gets created in your project. You can put your input file at the same location and it should work just fine (if it doesn't, you should check your resource pattern which might be causing the file to be not copied over in the build output).
This method actually gives you the working directory of your intellij settings which is pointed out in the accepted answer. Just sharing as I had similar trouble and I figured out this way. :)
By default svcutil.exe generates proxy class and its .config in C:\Program Files\Microsoft Visual Studio 9.0\VC.
What is syntax for generating a proxy class in a specific project by using svcutil.exe ?
Use the /directory option.
To quote directly from the help which is displayed when you type svcutil /? :
/directory:<directory> - Directory to create files in (default: current directory) (Short Form: /d)
Just to elaborate a little more... svcutil just generates the files, it doesn't manipulate the .proj file to add a file to the project, you have to do that yourself. What you might want to do is:
show all files in the Solution Explorer, then refresh the folder containing the generated files, then select them all and add them to the project (you should remove the existing files before doing a manual generation)
write a little batch script or command line app that iterates the folder the files are created in and inserts entries for them into the .proj file.
if possible use the Add Service Reference option from the context menu in the Solution Explorer, that generates the files and adds them to the project for you