I have multiple projects that are accessing the same settings (they were a single project, but I'm re-factoring). What I would like to do is the equivalent of:
"Add Existing Item" -> "Add Link"
The projects are a mixtutre of both C# and VB. When I try to do add as link, it does bring the settings file in, but it doesn't recognise it. I actually get the error when trying to load the settings:
Error HRESULT E_FAIL has been returned from a call to a COM component.
Is there a way to tell the project to use a specific settings file (either inside or outside the IDE)?
I usually put these things in a common library. When sharing settings, you probably share more than just that, so combine it then. When marking the settings as public instead of internal, you can access them across the other projects.
For future reference:
The solution was to add the Settings file 'as link' to the project, right click and hit 'Run Custom Tool' where the Custom Tool property of the Settings file is 'SettingsSingleFileGenerator'.
Note that this solution is not favored, since it depends on manually updating the settings designer file by performing the above actions.
Taken from MSDN: Add Multiple Settings
"In Solution Explorer, drag the new Settings file into the Properties folder. This allows your new settings to be available in code.
Add and use settings in this file as you would any other settings file. You can access this group of settings via the Properties.Settings object."
I have done this,and it works for me in my C#/VB mixed projects. Hope this helps
Related
I have Java background and am trying to start on C#.
I wanna create a lib in C# that will be used in other solutions. In Eclipse it's just a matter of creating a jar and adding it to classpath. I know each project in VS2013 becomes a dll, but how can I make a solution see these dll?
Also, in Eclipse, we can create a Web Fragment Project. It can have Servlets, jsp and static js and css files, it becomes a war file and can be imported into another project and its files be used in that project.
How can I do that in VS2013? I'd like to create a solution with static files, master page, some aspx stuff, C# dll, and then use them all in other solutions.
Is there any tutorial (I googled it but found nothing) teaching how to do it?
You have a few options depending on your preferences and scope
Option 1 - The Class Library
You can create Class Library, that can be referenced in your website project. The Class library is a library of classes, interfaces, and value types
You can either Add an existing/New Class Library project to your website solution and reference it directly
You can add the project to your solution by right clicking the
solution (inside VS) -> Add -> Existing project -> and navigating to said
project's .csproj file
or
You can use a new/existing Class Library Project - build it and reference the built dll in your website solution.
you can right click your website solution (inside VS) -> Add -> new project -> choose Class Library
After you've done one of the above ->
Right click the project, you want to add the reference to
Click "Add Reference"
navigate to the .dll in question.
If the dll you want to reference is part of your current solution (as in step 1) -> after you've pressed "Add Reference" - press the "Solution" Tab and it should show up
After you've added the dll.
Remember to reference it in your code files with
Using TheReferenceNamespace;
which will allow you to call the functions inside you dll like the following
FunctionInsideDll(param);
or you could fully qualify your calls instead, like the following
TheReferenceNamespace.FunctionInsideDll(param);
Option 2 - Share MasterPages
if you just want "shareable" masterpages
you can do the following - (taken from this -> MSDN article)
(for future reference - web archive link - just in case something gets moved)
Precompile the Code Used in a Master Page
If you are concerned about code in your master pages being visible to others reusing the pages, you can precompile the master pages' code into a library. In this library, you can include code-behind pages as well as user or custom controls. Compiling master pages does not remove the declarative code for the master files or any server controls used, but you can compile the master files to remove the code for controls or code-behind pages used by the master pages.
If you choose to compile the master pages into a library, you must use the "updatable" build option that allows for later modification of the markup. This option is determined by the Allow the precompiled site to be updatable check box in the Publish Web Site dialog box. For more information about precompiling pages into a library that can be reused, see Building Re-Usable ASP.NET User Control and Page Libraries with VS 2005.
Option 3 - The template
Create a template, and use that template for different projects
In Visual Studio - Press "File" -> Export Template -> follow the wizard.
After it has been exported and you've imported it (either through a checkmark in the wizard or double clicking the vsix file) -it will show up under your project templates when you create a new project.
You can include a project from solution A in solution B by right-clicking on solution B and choosing "Add existing project"
Don't be afraid to edit XML .csproj files. For instance, this works ...
<Compile Include="$(Codez)\z.Libraries\diff-match-patch\DiffMatchPatch\**\*.cs"
Exclude="NotThisOne.cs;**\NotThisFolderWith\This*.cs">
<Link>Libs\%(RecursiveDir)%(Filename)%(Extension)</Link>
</Compile>
...and will give you all the C# files from the source folder, and subfolders, as linked files in your destination project under a folder called \Libs\.
$(Codez) is a Windows Environment Variable I use on my PCs.
I also could have used *.* at the end instead of *.cs.
This is one of those things Visual Studio might break on you, adding a file into the folder full of wildcard-linked files may break them out to separate entries. Or not. Depends on the wind.
I'm making a DLL in C# that I would like to be visible in COM without registration. Following instructions elsewhere I have generated a new "app.manifest" file in the project and edited it to include the COM information I need rather than the generic UAC information.
Except Visual Studio won't let me use it instead of the default manifest. When I open the project's properties, the manifest dropdown is disabled:
What do I need to do to select & embed the custom manifest I've added to the project?
Edit: The "app.manifest" file is in the project's Properties folder. As described here, for registration-free COM I need to change the Manifest from embedding a default manifest to using the manifest in Properties. Except it won't let me change that setting for some reason.
Edit 2: The Manifest dropdown is enabled when I change the output type to Console Application or to Windows Application. Why would it be disabled for a class library when MSDN explicitly states that a manifest is needed for registration-free COM libraries?
Class libraries don't need to use that dropdown to embed a manifest.
Important Note: Pretty much the only reason you would embed a manifest into a C# library this way is to make it available for use via registration-free COM. If you're not doing that, you don't need a manifest and these steps are not for you. Go away.
If you use Add -> New Item -> Application Manifest File to add an app.manifest file to the project:
...and keep it in the project root (not in Properties, or any other subfolder):
...it will automatically be embedded into the DLL.
You can verify that it was automatically added by using File -> Open -> File to open the DLL once it's built and confirming that it includes something called RT_MANIFEST:
Special thanks to Hans Passant for providing all this information, albeit spread around half a dozen answers to different questions rather than all in one place.
I have a solution in visual studio where one project (.csproj) is set to create an exe.
I would need to create a duplicate copy of this project so that I can name it something different and change the icon for it. (All of the rest of the projects can stay the same)
I am using conditional compilation symbols for that project, but I don't want to create a whole separate solution configuration because that requires expensive rebuilding of the entire solution.
In Visual Studio under Build -> Configuration Manager, you can create a new configuration for your project and clone it from your release build, then in your project properties you can customize it.
For the icon, you'll want to refer to Set a different ApplicationIcon for each build configuration
Create a copy of the project on disk (outside Visual Studio) and add the copied project to the solution. Then you can modify output assembly name, icon. etc..
However better practice would be to perform the necessary operations as postbuild step (e.g. batch/powershell script) as you will have to keep the projects synchronized (added/renamed/removed files, references...)
Copy it somewhere else and change the assembly name and namespace may be on the project property window( right click and property)
I dont know what your trying to accompish but possible solutions:
add post build event that will copy exe / (exe ad dll-s) to another directory
if you use TFS, edit your Build so it will create copys
Cheerz,
I have an app MainApp that references another project MyDLL.dll. Inside the MyDLL project I have made some user settings in a Settings.settings file that may be changed at runtime. So it appears that these settings get saved in the app.config file of MyDLL. But the problem is, the main project is MainApp, and MyDLL.dll.config does not, so far as I can see, get copied to the MainApp output folder. This is reflected in the fact that even though I save the settings in the code of MyDLL, the next time I run MainApp the settings have gone back to the default.
I must be missing something really obvious here. There has to be a way for related assemblies to preserve their settings values. But how?
While you can add an app.config to a library project, it has no effect to do so. Configuration is linked to the application, not the library.
You need to create the settings and configuration in your application itself. You can do something like including the library's app.config if you really wanted to, but that would probably not do what you want, either. It's best to just handle your configuration in the application.
Why is this so? Because what's to say it's valid to have user settings for your library in the first place? A library should not be tied to any particular kind of application. What if you used it in a Windows Service or an ASP.NET application?
According to MSDN, one can add customized settings files to ones project for convenient management of groups of settings.
So I created a custom settings by visual designer, set all properties as a User Scoped to be able to save them.I bind some control properties to this customized settings. And change some values mannually through Properties.CustomSettings.MyValue = x;
But when I do Properties.CustomSettings.Default.Save() - nothing happens. The changes are not persisted between application run (I'm aware about Debug version change) .
I searched a file in the directorites that ConfigurationManager gives me (according to this post) but didn't find any track of this CustomSettings.
So, what is the trick with saving this Customized Settings Files and How to save Customized Settings Files?
Ok, now I've got a right answer. Everything is OK that this custom settings were created under the dll file.
The problem is with this question
Application.UserAppDataPath strange behaviour
If one have AssemblyVersion with automatic Build and Revision Numbers and have AssemblyFileVersion in AseemblyInfo.cs, say, of exe that uses this dll, then Application.UserAppDataPath will throw ArgumentException "Illegal characters in path." Application.UserAppDataPath is used to build path to this config file to save this CustomSettings.
But ApplicationSettingsBase just eats all exceptions that happens inside, so the file is just not saved and nobody could even think about AssemblyFileVersion in AseemblyInfo.cs of exe...
Ohhh my god... 8 hours of fighting with this ... feature...