This question already has answers here:
Can a class library have an App.config file?
(7 answers)
Closed 4 years ago.
I have a (very) old c# desktop app which I've inherited and I need to move hard-coded values into a settings class. This setting class belongs to a class library. However when I publish the main project (which is the windows application) none of the settings from the class library appear in the published app.config.
So : have a VS 2017 solution with two projects: a class library and a winforms app. Both have a Settings.settings class; but when I publish the winforms app the resulting app.config only has the settings from the winforms app project.
Do I have to move the settings from the class library to the main project to have the published in the app.config? (which would seem odd as the code for the front-end doesn't use these settings directly)
Or is there some way I can ensure the settings in the class library are included in the app.config when publishing?
The "App.Config" file is populated from the "resources" tab in your project properties.
If you make a "settings" class ('SettingsClass.cs'), this will indeed not visibly show up in the compiled product. such a class is useful to make it easier to find and change values during the design process, but it does not allow for easy updates (although it also makes it harder for end-users to inspect said settings).
if you want to be able to easily see and change values in the compiled product (trough an updater, for example); you will need to use the project properties, or use some other method (excel file, xml file, sql database), with a (custom) reader class
Is it really possible to have a two different asp.net web projects in a single web solution ? For instance here's the current structure
+Solution
-CoreModule
-CustomModule
-WebProject
In this same hierarchy, can I have this
+Solution
-CoreModule
-CustomModule
-WebProject
-NewWebProjectModule
And use the web pages defined on NewWebProjecModule inside WebProject and use the style defined in WebProject inside NewWebProjectModule ?
What I am trying to do is separate the modules in the web project to have less clutter ?
Or would I be better of doing a control library as different project OR have the business rules on a separate module and have the UI on the main web project ?
First, you can very much have more than one web project in a Visual Studio Solution. While debugging with VS, you will have to run the required one.
If you have contents/controls that get replicated/reused in both web projects, I would prefer to have them in a common library/module and use them as required.
I've got a Prism project with a dozen modules in it.
I want to use a custom font (a .TTF file, to be specific) in all the modules.
When I put the .ttf file in the module folder - it works, but what if I add a dozen more modules?
So, I want to have the file in one place.
At tried to put the font in %projectname%.Web/Clientbin, because it worked with images and everything, but it doesn't work. =(
Can you give me some advise?
Example of the code:
<HyperlinkButton
FontFamily="/fonts/AZGR45_C.TTF#AZGaramondC">
www.samplelink.com
</HyperlinkButton>
Using PRISM generally means you have a few projects.
Application.Shell: Your startup application containing the app.xaml
Application.Module: Your different modules
Application.Infrastructure. Containing general classes for your
application. Every module and the shell has a reference to this
project. In example you might have Interfaces for certain services
like CustomerServices. This also allows you to have certain styling
or datatemplate or even fonts in this Infrastructure project
Hope this helps
The java build tool "maven" has a standard directory layout for projects. What is the equivalent type of directory layout for a C# project? I'm just learning C# and .NET and it seems that the IDE just dumps everything into one directory, heh. Does C#/.NET follow a convention for the directory structure?
EDIT: This would be for a desktop application (windows forms or wpf). I'm looking at one of these two, but I don't know enough yet to really know which one. Ultimately I would like to learn both.
In C# directory layout should be strictly related to the namespaces you have. Each directory creates subnamespace. Here you may find instructions how to name namespaces properly.
If you use FxCop, it will inform you if your directory (namespace) layout is OK. The main rule is that there shouldn't be namespaces with a few classes/interfaces (FxCop suggests merging two namespaces into one in such a situation).
I think that's all I can say without knowing of some special project type (Uwe mentioned some of them in his comment) you have in mind.
Usually you get the following structure in your project :
/bin/Debug (after a DEBUG build)
/bin/Release (after a Release build)
/obj/Debug
/obj/Release
/Properties (contains AssemblyInfo.cs + Resource files when added via the assembly's properties)
/ServiceReferences (contains service references if any are present in your assembly)
In addition to the above, any solution folders you create (via r-click solution explorer -> add new / folder) will be present in your project's folder.
Does this help?
How can I have code-sharing between two projects without making a dll?
The issue is: I have a tool that syncs users & groups from LDAP to a database.
Now the tool is a windows service, but testing it as such is very difficult and time consuming.
Which is why I made a console application where I can test the LDAP syncing, and then just copy the respective sourcecode-files over to the service project.
But... keeping the common files in sync is a bit of a problem.
I don't want to make a dll, because this probably creates me a problem with
the 3rd project, a windows installer (for the service) where I have to use ExecutingAssembly path...
Is there a way to share the code without making a separate dll?
Automagic statical linking, so to say ?
How about adding a file as a link.
In Visual Studio right click on your console test app project -> select add existing file -> in the file add dialog navigate to files in your actual windows service project -> select the files you want to share -> and on add button select add as link option.
You can add a file to a project as a link. On the Add Existing Item dialogue the Add button has a drop down on its right. Use this to select "Add as Link":
Put the file as a solution item and add as a link to each project.
How about hand-modify the project files to point to the same source file?
Another option - put both projects in the same folder. Add a class to one, then in the other project add existing class and point to the class just created.
You could:
maintain the shared code in a separate project that produces a DLL and then use a tool such as ILMerge to turn the DLL & EXE into one assembly.
share the source-files between multiple projects, either by tweakiing your project files or doing something funky with your source-tree layout.
All that said, the best approach would be to bite the bullet and store the shared code in a shared assembly (DLL). What happens when you decide to, for example, expose this code via a WCF service? It starts getting more complicated then as you have 3 places that reference the same code files. Don't just think about what makes your life easiest now, think about what'll make your life (and that of anyone else who has to maintain the code) easier in the future as well! =)
Necromancing - As per Visual Studio 2017:
You can create a shared project, and then reference the shared project in another project.
It will use the framework-version and libraries from the project you reference the shared-project from. You can also use the same shared project in multiple projects, provided you get no conflict.
This is basically statical linking on a source-code level.
This also works with HTML&JavaScript-files (specifically, it works with publishing), but with HTML & JS files, you will run into problems while debugging...
It's under "Classical Windows Desktop", but you can also use it for .NET Core etc.
If you want to share functionality, you should use a DLL or similar.
Since what you want to share is the source, what you are essentially sharing is file sharing. So you can do that by making your projects reference external sources or you can have your source control do this for you.
If you are using Visual SourceSafe, you can make a link between two folders. VSS will make sure that they are treated as the same file.
I'm going to describe the setup we use to manage and test our Windows Service projects. While this doesn't answer the question of "sharing code without a DLL" (Unmesh's answer takes care of that), I think the OP probably doesn't realize how easy this is with a DLL. In any case, I'm hoping it will help someone.
Create a solution, LDAPSync. Create three projects in this solution:
LDAPSyncLib
LDAPSyncSvc
LDAPSyncTest
LDAPSyncLib is a DLL project that contains all of your business logic and main functionality.
LDAPSyncSvc is a Windows Service project that contains two classes, a service controller class that inherits from ServiceBase, and an Installer class for your service. This project has a "project reference" to LDAPSyncLib.
LDAPSyncTest is either a GUI application (WinForms, WCF, etc.) or a console application, depending on your needs. This project also has a "project reference" to LDAPSyncLib. Its sole purpose is to provide some interface which allows you to easily make the required calls into your business logic for testing purposes. In Visual Studio, set this as your "StartUp Project".
Now, when you run in debug via Visual Studio you will get a nice little GUI or command window that you can use to manually make test calls. When you install it as a Windows Service, the LDAPSyncSvc project's controller class will take over and handle all of the necessary service requests (start, stop, pause, etc.)
We have around 30 in-house Windows Service projects that we've been continuously managing, developing and testing for over a decade and this workflow has proved invaluable in quickly finding and fixing bugs when they arise. Best of luck with your project and I hope this helps some future Googlers.