How to add a shared resource in a multi project solution? - c#

I have a solution in Visual Studio 2013 that hosts different projects of different types (three Windows WPFs, one WebAPI and a Windows Service)
something like this:
I want to add shared resources like string tables (global messages, common errors, etc) in the resource.resx file that is accessible to all. Ideally this file is placed in the "Common" folder and this common folder has been placed in the root of solution folder.
How can i do this?
I've tried with below steps:
Adding a "New Solution Folder" to the solution and "Add"->"New Item..." but there is no new "Resource File".
Create a new "Common" folder in windows explorer, drag and drop it from windows explorer to solution explorer. but by this method i was just able to add it to projects not folders(and even in projects, VS "copies" that folder to project folder and changing files in that project only affects copied folder and not the common one)

You can put all your resources in a shared project.
Create a new project, call it, for example ParkingResources.
For any project that requires these resources, add a reference to the new project.
In your consumer projects, you should now be able to access the shared resources.

Related

Visual Studio Project rearrange project into folder with same name

Project name is testProject. I want to create a new folder named "TestProject" and move the project into it, because I want to add testProject.uTest and testProject.iTest for unit and integration tests. So everything related is located in the same folder.
The solution is in VSTS. Already one folder exists with the same name because of the project. Namespaces will all change.
How do I go about this the best way?
I got everything to work.
First I opened the solution and deleted the project in there. Then I created the new folder in the solution explorer. I then copied all the project related files into the new folder in windows explorer. I opened up the solution and added this existing project and add all files to source contrl. Next I had to re-add nuget packages and fix some references in other projects. Next I pushed the changes and then I deleted the old project files in source control explorer.
Took 10mins and everything works fine!
A few simple steps that worked for me:
Create a folder and add some text/number at the end:
Example: Infrastructure1
Create/Add the Project to your solution without the text/number at the end.
Example: Infrastructure
Rename the folder (Infrastructure1) to match your Project name(Infrastructure).
That's it, and you will get rid of the message that Project can't be named with the same name as the folder.

Where to copy a 3rd party assembly in your Visual Studio project?

My operating system is Widows 7. I am using Visual Studio 2015.
I have a solution Sln1 which has 2 projects Proj1 and Proj2 both projects are of Class Library type.
In Windows Explorer I can see:
I have a folder c:\MyWork\Sln1 which has the solution file named
Sln1.sln and it also has 2 folders named Proj1 and Proj2.
I have a folder c:\MyWork\Sln1\Proj1 which has the project file named
Proj1.csproj and it also has 3 folders named bin, obj and Properties.
I have a folder c:\MyWork\Sln1\Proj2 which has the project file named
Proj2.csproj and it also has 3 folders named bin, obj and Properties.
I have a 3rd party assembly (Telerik.Web.UI.dll) which is in folder C:\Program Files (x86)\Telerik\UI for ASP.NET AJAX Q3 2015\Bin45.
I want to use this 3rd party assembly in the source code of Proj2 only. But I dont want the project Proj2 to access it from its current location. Instead I want the project Proj2 to have its own copy of this 3rd party assembly. How can I do that?
Copy the dll file to the desired location for example (solution/project/lib). Then in vs2015 open the solution explorer Ctrl + Alt + L.
Then under the project, you want to add the lib to right-click on reference.
Then click on add reference. Go to the browse tab and in the right bottom side click on browse.
Here you can select the dll you want to reference in the project. The 3th party library is now ready to use in your project.
Since you want the 3rd party library in the "Proj2" project location, just copy the DLL file (i.e. Telerik.Web.UI.dll) to a folder in that section (for example under lib, etc.) then in your project(s) go to your Solution Explorer, under the References right click and choose "Add Reference...", then click on Browse and choose your DLL accordingly from the location that you copied earlier.
I hope this will be a useful tip for you.
The most important thing to take into account is version control. No matter where you put it, make sure that the library is under version control, or at least that sufficient information to retrieve it. Also, check that you reference it in your project using relative paths, so anyone can build using only files within his own working copy.
I generally use a structure like this:
\
\libraries
\lib1
\lib2
\source
\proy1
\proy2
So that it's easy to checkout the whole thing, incluiding all dependencies and use those for building everything.

how to new project and deploy it to a virtual directory of an existing site?

I have already Existing project. I have created new project . I want to new project and deploy it to a virtual directory of an existing site. I want to install MVC forum NuGet theme my Existing project. i am following this way
Create a new project and deploy it to a virtual directory of an existing site.
Having 2 separate projects doesn't mean they can't run on the same site. Unless you have a specific reason for wanting it to run in an existing project (like view injection/route hijacking).
If so... It's hacky (really hacky) but you can create a new C# project in a subfolder of an existing C# project. Create a new solution in that sub folder to. Load the subfolder solution by itself and add the sub folder C# project to it. Add MVC Forum to it and save. Then close that solution and open the parent solution and click show all files and add the subfolder to the project while excluding the .sln and .csproj \bin \obj etc.
So structure would look like this,
Existing Project:
MVCForumSubFolder
MVCForum.sln //exclude
MVCForum.csproj //exclude
Views //include
etc
On another note, I'm going to dive into building a NuGet package generator for MVCForum soon and if possible I'll have it prompt to do a root add or a subfolder add (subfolder assuming virtual directory configuration).
how can do this new project deploy it to a virtual directory of an Existing Site ?
If you are using Windows Azure for deployment. Then look the following link for how to create a virtual directory in windows azure.
http://blog.logiticks.com/virtual-directory-in-azure-website/

.NET (Visual Studio) Share assets between projects

I'm working with Visual Studio. There I have a solution with several web-projects (.net MVC 4). All of these web-projects use the same javascript-libs. Currently I copied the library into each project, but this can't be the final solution. What is the best approach to share those library (assets in general) between all of the projects? Just link them? Or is it possible to create a project and reference it in all projects?
Update
"Link" the javascript files from another project is not a possible solution as I would have to link thousands of files (one of the libraries I am using is ExtJs) what makes it impossible to build a project without freezing visual studio...
Possible solution
Currently I have a (Web) MVC Project called "Web" and a (Class Library) Project called "ClientScript" which contains all the JavaScript files which are shared between several Web Projects. As linking all the needed JavaScript files is not a possible solution (because it's a matter of thousands of files what causes visual studio to freeze) I copy all the needed JavaScript files to the individual Projects using the Build Events in each Web Project (Project -> Properties -> Build Events -> Post-build).
My Post-build command line in the Web Project looks like this:
start xcopy "$(SolutionDir)ClientScript\Frontend\*" "$(SolutionDir)Web\Scripts" /r /s /i /y /D /E
Every time you build your Web Project all the changed Javascript files get copied from the ClientScript Project to your Web Project.
While developing the Javascripts I run a small "filewatcher" tool which automatically copies a file from the ClientScript Project to every Web Project when it changes. This way I don't have to build the Web Project every time when I make a change to one of the Javascripts.
Anyone that stumbles across this question here in the future should know that there are now Shared Projects in Visual Studio to solve this problem. Universal Windows projects use them by default and you can create your own by downloading and installing the VS extension here: https://visualstudiogallery.msdn.microsoft.com/315c13a7-2787-4f57-bdf7-adae6ed54450
Note: At this time they can be picky about what type of project you try to add the shared reference. I created a JavaScript shared project to share js files between a Windows store js app and an MVC web app and it would not let me do that saying they had to be of the same language. (It supports C#, C++, or JavaScript).
Place the JS files in a single folder, likely above all others, and add them to the project but use the "Link" option. It's part of the drop down on the "OK" button in the "Add existing item..." dialog.
When you run every new ASP.NET MVC 4 project it's take a new port then other app have take.
I simply suggest you a simple thing.
run a project which contain all the pacakages. open them webmatrix and run them as localhost:80.
You need to set the port in settings section of your site in webmatrix. Now it will rechable at localhost now you can reference all the libraries from this packages.
Slightly older thread, but I have another way of doing a similar thing using Web Essentials, that handles the issue of not publishing correctly.
I have a shared folder outside of the projects that require the shared file, normally a 'common' project with other things in as well, but can be just a simple folder as suggested by Michael Perrenoud.
However instead of 'Add as Link' I have been creating a new bundle in the project that requires the shared js/css file, with the same name as the shared file, and then referencing that file in the shared folder using a relative reference location rather than the root based one it starts with.
To add a file from a shared folder in the root of the solution to the scripts folder use the following code in a new bundle file (*.bundle), changing the folder/file names as required.
<?xml version="1.0" encoding="utf-8"?>
<bundle xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://vswebessentials.com/schemas/v1/bundle.xsd">
<settings>
<minify>false</minify>
<runOnBuild>true</runOnBuild>
</settings>
<files>
<file>../../MySharedFolder/my-js-file.js</file>
</files>
</bundle>
Then every time you build it recreates the bundle with the latest version, this version is then also published as expected :)
You can even create a minified version if desired by changing 'minify' to true. Or better yet you can add them loads as a bundle too if you want, you have that flexibilty.
This is an older thread but due to complex business requirements these days applications are divided in to different modules or sub projects.Thus, brings us the need to share common resources like JavaScript files, themes and CSS style sheet files.
I personally feel that common files should be put in separate Asp .Net MVC 5 project which has following structure :ASP.NET MVC5 folder structure
Now the best part is you can separately manage the dependencies using Bower,NPM or Nuget package manager.
After you have organised all the files in this project host this project to your own CDN or may be on cloud. You can use Using CDN in Bundle Approach to get script or link references.
That will help you sharing common resources across all the projects.There us a short coming though if you have many developers on the team and if someone added incompatible version lib can affect all the apps.

How can I put files in the user's local application data folder in a setup project?

I'm working with a visual studio 2008 - You get access to a number of special folders to use if you want to include files within. One I don't see on the list is the user's local application data folder. Is there anyway to put files in that folder from within a VS2008 setup project?
When I was facing similar challenge, I made it so:
Created a class library auxiliary project.
Added the System.Configuration.Install.dll reference.
Added a new class inheriting from System.Configuration.Install.Installer
Wrote an override of the Install method to copy the files
In the Setup project, targeted the above mentioned project output to the Application folder and -
In Custom actions (Install group) picked the auxiliary project output from the Application folder.

Categories