Referencing XML file in a referenced project? - c#

I have a utility project that has an "XML" folder with two XML files in it, this project is then referenced by an ASP.net web project. I was wondering do you have to set some sort of build option to place the folder in the BIN of the website, or is there another approach to referencing these two files from the web project?
Thanks

Select one of the XML file in the solution explorer, then in the properties list you should see a property called "Copy to Output Directory", set this to "Always Copy".
Do this for both files.
That should then bring the files into the referencing projects bin folder.

Related

Files do not show up in solution explorer, even when added to project

I inherited a codebase, and one of the projects has a few hundred c# files, but in solution explorer it only shows a couple. These classes are referenced in other projects, and the solution builds fine.
If I click the "Show All files" option, it will show the obj and bin folders and a config file, but none of the .cs files that exist in that folder show up there. If I go to project -> Add Existing Item and select one of the files, the project does not change. All the files I'm looking for exist in the appropriate folder.
Why are the files missing in solution explorer, but still referenced in the codebase? How do I get them to show up in solution explorer?

How to send all .cs files to output directory after every build in Visual Studio 2012.

I have some project what contains 3 dll libraries (one of them has 2 dependencies)
At the output folder of 'DLL parent' I need to have all source files of this 2 children. Moveover I want to save structure of this cs files by making 'cs' folder at output folder of DLL-parent, create subfolder with DLL-Child name there and copy all cs files of it to this folder.
For doing this I use post build events for DLL-Child.
And at bottom level when I build just this dll it works perfect.
After I set this command line at DLL-Child post build event it's output is created with folder with source files inside.
But when I build whole solution problem that this folder is not copied from output of DLL-Child to output of DLL-Parent.
Why ? At references section of DLL-Parent I set 'Copy local' to true for dependencies but it copies nothing.
Have your files be exported in separate folders per project. With this simple post build script (it's better to set it as post build event and select on successful build so as to not copy it each time but only when a build has been done properly)
copy "$(ProjectDir)FolderName\*" "PathYouWantYourFilesCopiedTo"
You can output all files from specific folder in your project.
You do not need checks for folders existing, VS does it on it's own. Create one build event for each folder of your files. If you have them in separate folders, nothing will overwrite nothing (as long as you maintain the folder structure in the output). And copy a whole folder is easier than copying file by file.
Basically what you need to do is to specify explicitly folder names for the output location. That will stop overwriting of files.

Reference a resource to be copied at build time

In Visual Studio, I can add a resource (text file, image, etc.) to the project and have it copy to the output directory at build time. The problem with this is that the project copies the file into the project directory. I have a multi-project solution where many projects are referencing the same resource, I don't want the resource copied into every project directory. I want the resource to stay in a separate resource directory that I have under source control with the rest of the solution. Is there a way for me to add the resource to the projects and have the projects copy the resource to the debug and release directories on build that wouldn't force the file into the project directory?
In project explorer select the folder or project where you want to add the file and right click. Select Add Existing Item from menu.
Locate the file and click on the arrow near the Add button. From the menu opened, select Add As Link.
Do not forget to change the properties of the linked item (Copy To Output directory etc).
You should be able to link the files into your projects instead of copying them. See http://support.microsoft.com/kb/306234 for steps.

Publish dll - copy to bin folder

MVC project.
On my data access layer I have a libs folder where I store some dlls that the project needs t oaccess data. One of them is set "copy local" to true. The goal is to copy the dll to the bin folder so I can deploy it with the application.
The thing is, when I build the app, it does copy to the bin folder, but to the bin folder on the DAL project only. Since it is a web applicaiton I want to build the web project and have the dll copied to its bin folder so I can just deploy it withou having to manually coping it from the bin on the dal to the bin of the deployed appliation.
What do I need to do to accomplish that?
Build Action = Content might help; but then it will only come in to your DAL Bin if it is referenced there.
You can right click on the web project and than click on Deployment project as given below ..this will add all required dll for your project in the path of your poject which you can see in ouput window

How Are References Handled in a VS2008 Website?

I'm creating a web service that uses multiple DLLs, some of which are projects that I have developed and others are external DLLs. Those that are external, I have simply copied into the Bin directory of my WebService. However, those that are from my own projects I have added as references by right clicking on the bin folder and selecting add reference. This adds both a dll and a pdb file to the bin folder. However, when I build the website, I am not sure where these two files are pulled from. I need to know because I am trying to encrypt these DLLs as a post build step on the web service and I need to know where I can find the DLL I should encrypt. Need any more information let me know.
If the files are part of another project in your solution, then open the project folder for those projects (right click on the project node in VS and choose "Open In Explorer..."). There is a bin directory in that folder that the assembly for that project is placed in after it is built. When the web site project is built, the assembly is copied from this bin folder into the bin folder for the web site.
EDIT
As discovered (in the comments to this answer), VS actually copies assemblies from the obj directory rather than the bin directory.

Categories