Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I wanna publish my app to my friends,and make for them installation as easy as possible so my app use SoundPlayer which needs file to play the sound. My question is how can I know where will they have this file saved?
I used this code:
SoundPlayer music = new SoundPlayer(ApplicationDeployment.CurrentDeployment.DataDirectory + #"\songfolder\Main.wav");
That gives me error: The application identity is not set.
PS: sorry for my bad English :D
Are you talking about publishing projects via ClickOnce? You can go to Project -> Properties -> Publish and check if the required files are included in Application Files.
Solution Explorer:
Application Files:
And you need to use the following code to access these files.
string filepath = AppDomain.CurrentDomain.BaseDirectory + #"songfolder\song.mp3";
Last, click Publish Now to publish it.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
After building the release version for my application, I went to the bin/Release folder and saw a bunch of my project dependencies, such as "Newtonsoft.Json.dll", "System.Memory.dll" and so on.
I have referenced posts like What files are mandatory in release windows form? and saw that these dependencies are needed for my application to run smoothly.
However, I only needed to copy one file - my "main.dll" to the application (I'm creating an add-on for Revit) and it works fine. So, I'm wondering which files could be excluded? This is because my application is still being modified and new dependencies are being added, and I would like to know which files are not needed.
Is there a list of dependencies that have already been included in windows automatically?
In short, you probably need them all and sometimes some. The long version -- it depends. Below is not an exhaustive list but some points to consider:
Whatever is part of the .NET framework that you are using is not normally copied to the output directory
The examples that you listed normally should be copied to the output as they are not part of .NET Framework
You can force a reference to be copied by setting Copy Local to true, which would result in a potentially unnecessary DLL in your output directory
You may have some dependencies in the GAC, which means they might not be copied to the output directory. For example, are you using Infragistics, etc. controls -- do all of your users have them installed on their machines? Probably not and they probably shouldn't, so include them...
The compiler is generally smart about not including things to which you have no actual code references (this can lead to problems if there are dynamic invocations only)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
The application that I've released works very well in any folder, except:
E:\Csharp\NewMacaron\WindowsFormsApplication1\WindowsFormsApplication1\bin\Release
That's the release folder.
The following error is produced:
There is no bug in VS 2008 in regards to the issue you're experiencing. You somehow corrupted your manifest file or most likely, the config file (macaron.exe.config). The likely cause is that it contains invalid XML and it hasn't been overridden by a default version.
First, try this:
BUILD > Clean Solution; BUILD > Rebuild Solution. In that order.
If that doesn't fix the issue, you need to look into your *.config file and check to make sure that you didn't leave off a closing bracket or have an extra quotation mark in there somewhere. If there is no sensitive information, post your configuration file contents in your original post, so that we may check it for errors.
Last, but not least, if you're still having issues, there could be a possibility of the specified .NET framework incompatibility with the machine or some of the references you're using, as specified in the config file. Since it is specified in the *.config file and it may be off from what you're working with, it could propagate into the error you're seeing. I am not sure if you've created that project on your current machine or if you've imported it from somewhere else, but it maybe that you need to go into your project properties and change the .NET framework version to your desired target version. This will override the supported runtime in the configuration file. The reason you may not be seeing the error in other directories could be due to the fact that you're not copying the configuration file (we don't know, since we don't know everything you're doing).
I have searched for other postings asking this same question. The typical answer is "use app.config instead".
All of the responses saying "use app.config instead" are useless. I do not want to read from app.config, I want read from web.config. If I wanted to read from app.config I would not have to be asking this question.
If you want to have a reason, I need a console app in order to be able to be scheduled for automatic execution. It must, however, share the same configuration as the web application that is installed on this machine. So stop trying to avoid the issue by saying "use app.config instead" and answer the question -- or come right out and say it is not possible.
Please, is there a way to access web.config (not app.config) from a console app?
I am currently using c# in visual studio 2008
Web.config is just an xml file. You can read anything form it using XmlDocument class. Load web.config into it and then use XPath query to find your connection strings.
I want to use a single app.config by 3 different projects.
How to access the configurations?
ConfigurationManager.AppSettings["config1"]
Let's say you have this folder structure:
Solution
Project1
Project2
Project3
Do this:
Create the App.config file in the Solution level folder. You won't find an option to add an App.config file from the templates, so just create a new empty text file with the name App.config, and paste in the contents of a regular App.config file.
For each project in Solution Explorer:
Right click and select Add > Existing Item
Locate the file
Select Add as link from the drop down box next to the Add button.
Edited to add:
You correctly state that the above method only shared the file up to build-time. To use a shared file at run-time, see the answers to this question.
The common config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section
name="appSettings"
type="System.Configuration.AppSettingsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
/>
</configSections>
<appSettings>
<add key="key1" value="value1"/>
</appSettings>
</configuration>
To access mapped config file
ConfigurationFileMap fileMap = new ConfigurationFileMap(file); //Path to your config file
Configuration configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
string value = configuration.AppSettings.Settings["key1"].Value;
I have found the button, and opened
the app.config as link, however that
caused when build to again create
separate config file for each project,
and therefore, when deploying the 3
project, i will have 3 config files.
What I wanted to do, is keeping a
single file for all projects in a
certain solution. Can I do that?
Yes - you can do it, but should you do it?
The basic assumption in a .NET app is that one app = one config file. Out of the box, and with an easy method, you cannot share config files between applications.
If you create your own custom config sections, you could "outsource" those to external files, which could be shared. Imagine you create your own custom config section called "MyConfiguration", then your app.config would look something like that:
<configuration>
<configSections>
<section name="MyConfiguration"
type="MyConfigurationSection, MyConfigurationAssembly" />
</configSections>
<MyConfiguration>
<nestedElement>
<dateTimeValue>10/16/2006</dateTimeValue>
<integerValue>1</integerValue>
</nestedElement>
</MyConfiguration>
</configuration>
You could have your "MyConfiguration" section in its own file, and reference it from your app's config:
<configuration>
<configSections>
<section name="MyConfiguration"
type="MyConfigurationSection, MyConfigurationAssembly" />
</configSections>
<MyConfiguration configSource="MyConfiguration.config" />
</configuration>
and your "MyConfiguration.config" would then contain:
<MyConfiguration>
<nestedElement>
<dateTimeValue>10/16/2006</dateTimeValue>
<integerValue>1</integerValue>
</nestedElement>
</MyConfiguration>
By doing this, you could "externalize" and thus share at least the bulk of your config settings - provided they're in your own custom config sections.
For more info and an excellent intro to .NET 2.0 and up configuration mysteries, see Jon Rista's three-part series on .NET 2.0 configuration up on CodeProject.
Unraveling the mysteries of .NET 2.0 configuration
Decoding the mysteries of .NET 2.0 configuration
Cracking the mysteries of .NET 2.0 configuration
Highly recommended, well written and extremely helpful!
Marc
Here's the "Add existing item" dialog in VS 2008:
Click on the little dropdown indicator on the "Add" button and pick "Add as Link" from the context menu.
Marc
One design option is to avoid accessing the app.config directly from your class library projects altogether, thus avoiding the extra external dependency.
Rather, only your executable project knows about the config file and it can explicitly pass the appropriate config information to the libraries when it creates objects from them or initializes them.
I understand this is a old question but there is a much easier way of achieving this. If you are using Visual Studio 2008 or higher there is a Project type called "Shared Project".
A Shared Project can have pretty much anything that another types of Projects can contain. This is not only for C# but for all languages that VS2015 supports. When something is included in the Shared Project it is available to other projects after you add a reference to it (see below).
The major difference with Classes in a Shared Project VS a Shared Library is when you compile the program everything that is in the Shared Project will be Compiled directly into your project not as a separate file (.dll, .exe). Think of it like everything that is in the Shared Project is inserted into the other projects. Here is a small tutorial on setting this up and using it:
Visual Studio 2015 - Shared Project Tutorial:
Create the New Shared Project by selecting File->New->Project or Right Click on the Solution in the Solution Explorer and select Add->New Project. When the Dialog shows up select "Shared Project", give the Project a name TestShared in this example.
After the New Project is added you can add anything you need to be available to other projects. In this case we will add the app.config. Right Click on the Shared Project and select Add->New Item. Select Visual C#->Data->XML File naming it obviously to app.config.
Finally add a reference to the Shared Project by Right Clicking the Project that you need to share the project with and select Add->Reference. In the Reference Manager Dialog select your Shared Project, it will be listed under the "Shared Projects" item on the Left.
Now everything that is in the Shared Project is available in the other project, there is no need to do any using imports or anything like that. It simply works. This pattern is quite handy when you are developing a program and need to have several different GUI's (Windows, iOS, Android etc). For example you could have one shared project for the "Core" functionality and then have a separate GUI Project for each of the different Operating Systems you want to support in your program.
I realize that this is a older question but since this showed up in Google I thought I would answer this so when others are looking for the same thing they know about this very powerful VS feature.
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config = ConfigurationManager.OpenExeConfiguration(Path.Combine(#"D:\", "config.exe"));
foreach (string key in config.AppSettings.Settings.AllKeys)
{
string value = config.AppSettings.Settings[key].Value;
ConfigurationManager.AppSettings.Set(key, value);
}