Settings file of a console app is not being created - c#

I have a solution which has 3 projects. One is a console app and other 2 are windows applications. Both windows applications uses console application so I added the reference of console application in both windows app projects. Now when I build windows projects, console application is being copied in output directory but the problem is that its config file "consoleapp.exe.config" is not being copied!
If I would have used a library (assembly) instead of console application, it would created the config file of that assembly in output folder.
How to solve this problem?

Try this:
Select consoleapp.exe.config in solution tree.
Select "Content" for Build Action option in property grid.
Select Copy always for Copy to Output Directory option.
Hope this helps you :)

Quickly creating a console project in VS2008 and adding an "App.config", it has settings:
Build Action: None
Copy to Ouput Directory: Do not copy
Custom Tool: <blank>
Custom Tool Namespace: <blank>
However I'm not sure what effect adding a reference to the console project will have, as a console project is an application rather than class library.
If you want the console application to start up with the Windows applications for debugging, then a better approach than project references would be to set the solution to start multiple applications. Right click on the solution, select properties and on the Start Project node, select multiple projects. (And remove the references to the console application.)

Your applications are using the default values for your settings from the compiled code of the referenced project.
You should copy your app.config from the other projects (or at least copy the settings that you want to be able to change) to the calling project, and then when the application compiles you will have an [YourAppName].exe.config that you can modify.
All this happens because an app domain in C# can have only one assembly level app.config file. Here's more information on MSDN.

Related

.NET project in a solution should generate an exe but only makes a setup file and shortcut

I've inherited an old .NET MVC C# website. Bundled into the solution is a 'SearchUpdater' program which seems to be some kind of service:
public partial class Service1 : ServiceBase {
It seems to be an application, on properties we see:
Output type: Windows Application
Target framework: .NET Framework 4
This somehow translates to a SearchUpdater.exe file we have on the web server which is run every day. The code deletes a search index text file and then rebuilds it.
Simple, except I need to update the code logic and replace the .exe.
When I do this I can't seem to generate the .exe file any way I try. If I 'publish' the SearchUpdater project I get a local 'setup.exe' file, which, when I run it generates a kind of SearchUpdater 'shortcut' in my start menu which is a
Type of file: Application Reference (.appref-ms)
Location: C:\Users\Me\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\HP Inc
There's no 'target'...
Basically, I can't find a .exe file anywhere to replace the one on our webserver!
Any ideas? I'm a bit lost with this one, how can I generate a .exe, and will I need to do this somehow on the webserver? Am I doing something wrong?
Thanks to suggestions by #codecaster and #hans-passant. If you build the project in release mode, then go to the solution folder and check in the correct bin folder there is indeed a 'release' folder that will contain the .exe file (or did for me!).

How to update the assemblies and file using setup project?

I've created a windows application in C#. The application has check for update feature. Whenever an update to the application is available, it downloads the setup file.
When we run the new setup it is successfully installed and we can see the new version in control panel. But the problem is that the assembly files and other files in installation directory are not updated. They are still the previous version of files.
I have set the following properties of the installer project:
- DetectNewInstalledVersion : true
- RemovePreviousVersion: true
Am I missing any property of setup project or is there any other approach to do that. I don't want to use any third party tool for setup creation.
You must increment the file versions of those files that need replacing. That's because of the Windows Installer file replacement rules.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa367835(v=vs.85).aspx

How to create two different executables from one Visual Studio project

I have a main executable that runs based on settings saved in a configuration file. I want to be able to change the settings in the config file through a different executable.
Is there an easy way of building these two different executables in one Windows Forms project? Meaning that when I press build, two different EXE files get created in the same solution folder - the one that changes the configuration file, and the other that uses it.
I know that this is possible to do if I create two separate projects that use the same solution folder, but I was hoping to do it all in one step.
I am assuming that to do this, I need a project with two "Main" functions. Is this possible?
You can build as many assemblies in one solution as you like. Assemblies can result in DLL files or EXE files.
Create a solution (or open an existing solution).
Right-click the root node in Solution Explorer and choose Add → New Project and choose the project type you like to add.
Right-click the project item in Solution Explorer and choose Properties → Build → Output path. Set to the desired directory where to build it to. Repeat this for the other projects.
This way you get the following in Solution Explorer:
MySolution
MyCommonCode (Class Library, results in MyCommonCode.dll)
MyMainApp (Windows Forms application, results in MyMainApp.exe)
MyConfigApp (Windows Forms application, results in MyConfigApp.exe)
The MyCommonCode assembly contains shared code that both EXE files are using like the identifiers of your configuration file, etc.
MyMainApp is the GUI application (Windows Forms, WPF, etc.) for your main application with a project-reference to the MyComonCode project.
MyConfigApp is a GUI application for editing the configuration values with a project reference to MyCommonCode project.
After building your solution you get the following binaries: MyCommonCode.dll, MyMainApp.exe, and MyConfigApp.exe.
Update based on the comment:
One compile-run can build only one binary (DLL or EXE) per project. You can do something like the answer above: move most of the code in a common/core DLL and make two thin projects for the two EXE files which only "configure and use" the central common/core DLL file.
You can build different EXE files based on the same project using compiler defines. You can even define your own defines. But per compile-run you can only build one binary (DLL, EXE) per project - one or the other, but not both.

how to deploy my application?

I want to deploy my application. i followed this step but i can't get the .exe file. steps:
Step I:
Create one Windows based application in VS.Net using any of the Languages i.e. C# or VB.Net.
Step II:
After your program is running and you are ready for the setup. To add setup to your existing application go to Go to File > Add Project > New Project.
After your program is running and you are ready for the setup. To add setup to your existing application go to Go to File > Add Project > New Project.
The window appears like below and you select the Project as Setup Project and give a Name and its Location.
Step III:
After creating setup project right click on project and than select view, it will show different possible operations, which you can perform with this setup project.
The options available are
File System
Registry
File Types
User interfaces
Custom Actions
Launch conditions
Step IV:
Click on File system, it is used to create file system on the target machine. Through this you can specify what details you want to provide at the target machine.
Step V:
Now in the new window, its time to add the files & folder’s used by the application.
First we add the Project Output file. Click on Project Output and a new popup appears. Select the appropriate choice. For a normal project we select as Primary Output File & Content Files.
it is used to create file system on the target machine. Through this you can specify what details you want to provide at the target machine.
To add Icons/Any specific folders, click on Add > Folder and Folder is added. Rename the folder as per your project requirements
After the Folder is create then add the files to the setup. These will be installed in the same fashion on the target machine
Step VI:
Now we are about to create the setup before that we will setup the program icon. To do it we will do this process :
When you click on Browse, a window gets popup. Now as the icons are already added into the application setup, just click on Browse to pint to that icon and click on ok.
Step VII:
Now final step is compile the setup project. After compilation you will notice that it has generated Setup.msi in the same location which you provided when you initially created the setup project.
You can supply this msi the target machine, when you run this msi at target machine it will create a virtual directory as well as create same folder structure, which you have specified in File System. This installer will also install the specified those libraries in the registry which are specified in the Registry.
Now you can browse that application at the target machine in same way as you have done at your own machine.
What I could understand is, you have got some problem with deploying the EXE file.
This is the best tutorial I have ever seen for creating EXE or MSI files:
http://balanagaraj.wordpress.com/2007/05/29/create-exe-or-setup-file-in-net-windows-application/

System.Addin & ClickOnce

I have a annoying build process from using System.Addins API with ClickOnce. Using System.Addins requires a specific directory structure, and the main project does not reference the adapters, view, and contract directly, which doesn't work well with the ClickOnce architechture.
The annoying part with the build process is that I have to copy, via post build event, the .dlls from the add-in components into the directory of the main app project, then reference those files manually from the main project, so that ClickOnce will include them. Firstly, this takes 2 iterations of build to get it to build correctly, secondly, it interferes with source control (I have to exclude the copied add-in dll files from source control or any changes made to them would require checkout).
So, my question is, is there a way around this hack? Something more elegant?
I can't fully answer your question, but it appears you are creating ClickOnce deployments through Visual Studio. I would ditch that method and use MageUI instead. It's a stand-alone executable that can be found in the framework SDK that will generate your application and deployment manifest files. It comes with a gui version (mageui.exe) and a command line version (mage.exe).
Mage may not get rid of your post-build event but it should do away with having to reference the files to get ClickOnce to see them.
Thanks for your input, I am currently doing it the way you mentioned; creating the folder in my project, and include the dlls that I need. It works, but it's an ugly solution, and it interferes with Source Control.
I'm aware of the limitations of ClickOnce, I was hoping there may be a way around it. For example, I read somewhere that I can use deployment projects to create the appropriate dependencies needed in a specific structure. The problem with that is once it is deployed to the public, there is no easy way (within ClickOnce) to update those dependencies.
The solution I use is to have a single output folder for all projects. Every project puts it's own files in the correct subfolder. The application bootstrapper project puts his dlls also in the output (root) folder. When you then create a click-ones for the bootstrapper, it will take all the content from the output folder.
The hardest part is to actually get all the dll's in the right place (and have every dll only once)
I solved this problem by adding the pipeline assemblies as content into the main solution structure.
To do this, change the output folder from (/bin/debug /bin/Release) to something else. I used ../lib otherwise you would get a visual studio cannot reference this file error.
Create the pipeline folders in your main solution
\AddInSideAdapters
\AddInViews
\Contracts
\HostSideAdapters
Right click on each of the folders and click "add existing item" change to view all files and then browse to your ../lib (or wherever you have the output set) and then pull down the add button (click the down arrow) and click "Add as a Link".
Right click on each file and set it to Content.
This will create a refresh file pointed to your assemblies and they will be included into the clickonce manifest.
ClickOnce do not let you install the software where you want. It will install the binary and dlls in the documents and settings. You can in your project properties go in the Publish tab and select Application Files to select additional file to Include. If the System.Addings require dll in a specific folder relatively to your assembly, you might just create the folder in you project and includes from here the dlls. This might works. If not, I do not have "hack" or other solution, clickonce is great but limited with some functionalities.

Categories

Resources