Linking files one solution to another solution is not working-- ASp.net MVC3 - visual-studio

I am working on ASP.MVC3 project. I created a base project where I will have all common files / pages like Master Page, Global.asax, Web.Config, Script files, CSS files, and images. And I have another solution which will contain module related stuff and I am linking common files / pages from first solution with “Add As Link” (Add  Existing Item  Add As Link ) option (I am working with VS.net 2010 IDE).
After linking all the files are coming into second solution and looking fine.
But when I run, the application is not running. Getting the message enable debut which already there.
when i clilck OK i am getting the error “the operation could not be completed. Unexpected error” (i think its expecting the physical file in the second solution location only).
After some R & D I placed the web config and global.asax directly (which is normal) in the second solution then the application started running. The same case for images / css / script files.
Please let us know the issue what we are doing wrong or is there any other way to share/link files from another solution.
Thanks in Advance.

You're probably better off doing it the other way around - create a website project and link your libraries / base classes to your project by adding a reference to them. This way you add all your images, css files etc direct into the website.
That's the more usual way of doing it in my experience, hope it helps.

The reason it doesn't work is because the linked files aren't copied to your working directory. To make your solution work you simply publish it to some other folder and it would re-create the site with copies of all linked files. There's no need to re-organize your solution as it would deploy all linked files once you publish it.

Related

Add a reference to a static folder from visual studio (2010 or 11)

I'd like to include some folders of static files shared between many projects and solutions.
These files could be images, script libraries or css that are shared between many projects.
I do not want to copy each time the folder inside the project structure but reference it just as we can link files between projects in the same solution so if any file changes in the referenced folder all the projects that link to it will have an updated version.
I know I can put it in a shared dll and embed resouces in it but I'd like to be able to choose witch folder to include.
Is this possible with Vs2010 or Vs11?
Sure, its possible, and not even that hard. Put the files in a well-known location in your hard drive, then add them to each project as a link. See the second section in the following article:
http://msdn.microsoft.com/en-us/library/9f4t9t92.aspx
If you use source control, I would strongly encourage you to have at least one separate folder per solution file, and nest the folder under your solution root somewhere. TFS, in particular, gets antsy if your solution file includes locations that are outside the current workspace. (It will work but you may get strange warnings or errors, particularly if someone else tries to get the solution for the first time.)

How to setup the target output path of a given resource file in Visual Studio

In the main project of my VS Solution I have a Resources folder with some required external tools. When building and publishing the solution, I get a .\Resources* with all required files there.
So far so good.
However I have to move some files to the parent directory.
My first attempt was do so with the Post Build Events. It works and does move them the correct folder.
Nevertheless in the publish output they still appear in the Resources folder and I need them in the parent one :/
Is there any way to setup the target output path for resources in Visual Studio?
After some research and experimental, I solved my problem.
Still, here's what I learned in the process.
The first attempt was adding the file to the project root and mark it as a resource. After publishing it worked. But having those files in the project root its lame.
Since I needed some *.exe files compiled in another VS solution, added them as a project reference. Gave it a try and it passed the "Publish" test. But still.. not the best way to do it.
After that, with some scripting and a post-build event, I copied the required files to the correct folder. Works.. but after publishing, they don't appear in the package.
However, there is still a possibility with the Mage tool:
http://msdn.microsoft.com/en-us/library/acz3y3te.aspx
This lead to some promissing experiments, however they ended up helping me realize how limited the MS ClickOnce is, so I decided to try other tools.
Here's a good start to follow:
What alternatives are there to ClickOnce?
I had a similar situation once. I found it became more trouble than it was worth to customize output paths and such in Visual Studio, to the extent that I wanted.
I ended up letting Visual Studio do its own thing with regards to file/project structure, and wrote a post-build script to copy everything that was needed into a final, 'publish-ready' directory.
I then set the execution target in Visual Studio to the new location, so I could run/debug as normal, but with the new folder that was organized how I needed it. Careful, I think this is a user project setting; so other developers will need to do this on their machines too, if they so desire.
I do recall changing some output paths and such to make the post-build script more simple. But changing things like that can lead to annoyances when you add new projects to the solution; you might need to configure them to match. It's all a trade-off :)
Two ideas:
Maybe you could move your resources into another project - a project just for resources - and then set their Build Action to Content and Copy To Output to true. Then reference this new project and build the solution. (This may not work as you want, just an idea).
Why not make your resources embedded resources instead. Keep them all within the Resources\ directory and access them programatically?

Where to put content, in Installer project (WiX) or in code project

So I see two solutions to my current problem, but I was wondering what the pros and cons are, or if there is a defacto best practices approach.
So my current project has a number of configuration files, help files, and other external content. I need this content local to run and debug the application. Currently we duplicate this content in a standard windows installer project. This clearly is a bad idea. We are moving to a new setup that uses the WiX installer, and I'm currently setting the project up next to the code project and trying to figure the best way to share resources. I see two solutions.
One is that I can put all the resources in the WiX project and then add them as links in the code project. This way I know what I'm debugging is installer.
The other option would be to leave the content in the code project and path into it in the installer using the reference variables.
Right now it seems 6 one way, half dozen the other. Any persuasive arguments for either method?
Assuming that these configuration and help files are going to be installed in the same directory as the executables then definitely put them in the code project, mark them as Content, and add a reference to the code project to the installer project. If you're using WiX 3.5 the files will be automatically included in the installer along with the executables, which makes writing simple installers much easier.
For earlier versions of WiX or more complex deployment scenarios (where the content files could be going into different directories) you would still put them in the code project but then you'd use File elements with a relative path or reference variable in the Source attribute to include the the content files from the code project directory.
I don't believe that putting the content files in the WiX installer project directory instead of the code project directory will do anything to ensure that the version you use to debug will be the same as the version installed. That can only be ensured by thinking through the process of how your application finds these content files and making sure the right versions are found.
So going back to the simple case where the content is in the code project and marked as Content, and it will be installed and loaded from the same directory as the executables, then it is only a matter of setting "Copy to Output Directory" to "Copy always" or "Copy if newer" and then you can be sure the versions used in debugging and the version installed will match.

How manage references in SVN/Visual Studio?

For a long time looking for a way to manage references, I haven't found any ideal way.
The main problems are:
1-) Should I include all projects that I use in same Solution and reference the Project? Or reference just the dll file?
2-) If I should reference dll file, the best way is to create a ReferencedAssemblies inside each project or a main folder at svn root?
3-) Its ok paste and reference dll´s inside bin folder of my project?
4-) Its ok add and commit dll´s inside bin folder of my project? This way when a new devoloper checkout the project, it will compile perfect, but isn´t default behavior of visual studio, all source controls ignore bin and obj by default, just adding .refresh files(for web-site project)
Someone can help me?
1) If you include projects in your solution that are already checked in somewhere else, you can change the SVN binding for that project at the solution level in Visual Studio. (File > Source Control > Change Source Control). You would change it to point to wherever it's located in your SVN repo.
2) If you have a lot of developers on different machines all wanting to use the same libraries, it's probably easier to have a common place for all your third-party libraries/assemblies. There's no point in having them copied all over the place in your SVN repository.
3) No, it's not usually ok to do this. I would avoid it (unless somebody has a valid reason for it).
4) Never commit your bin folders. The default behavior is such for a reason. The .refresh files are byproducts of the old Web Site projects and they are fine.
1) In the typical scenario yes, you should reference all projects that you own. But you should make a decision according to frequency of changes made to referenced projects. For example if you have an open source library it is better to include it as an assembly, cos you probably will not change this code frequently.
2) Typical approach is to create separate single directory at SVN root and place assemblies there in different sub-folders according to assemblies type. Here is how my current folder looks like:
3) No, it is better to reference assemblies from some other from bin folder. All referenced assemblies will be copied to the bin while building process. Also note that the purpose of *.refresh files in the bin folder is to prevent you from having to copy new versions yourself.
4) No, you should never commit your bin folder cos you can rely on *.refresh files for WebSites and just forget about this problem for other project types.
1) I'd argue it depends upon your particular situation, especially since Visual Studio is pretty flexible on what projects are included in solutions. (It's not tied to a directory structure.)
We have a couple applications that have one solution with a number of projects contained within (for each 'piece').
2, 3, 4) For referencing and including files within a project, why not just use the functionality built into Visual Studio? Adding references in this way adds the items to your csproj (vbproj) files.
(Based on my research, if you're not referencing a project that's part of the solution, put the DLLs in a directory everyone on the team can access and use that when adding the reference. In the project file it ends up looking like this:
<Reference Include="Elmah">
<HintPath>\\pathInformation\shared assemblies\ELMAH 1.1 32-bit\Elmah.dll</HintPath>
</Reference>
)
This also means that you don't have to commit DLLs; if anything changes the project file will be updated accordingly.
(I'll admit, I'm unsure about that last point. I've seen a lot of people check in external libraries, like ELMAH. I generally follow those who tell you to ignore the bin directory entirely.)

Visual Studio - Resource (CSS/JS/Images) sharing between web projects [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Handling common JavaScript files in Visual Studio 2010
I'm looking to share a common pool of web resources (css/js/images) across multiple web projects. What I'm hoping to do, is create one project file for the resources, e.g.: Common.WebResources, and include it in the Visual Studio solutions for Site1 & Site2.
The part I'm looking to solve is setting it up to work with the VS Development Server (the one that gets fired up on F5), and any outer deployment concerns.
So we're hoping to wind up with the following projects mapped to the following web directories:
Site1.Web - /
Common.WebResources - /resources
In IIS, it would just be a virtual directory. So far with VS Development Server, I've only been able to:
Get them to deploy on different ports (not a lot of use)
Add a post-build event to copy the contents of /resources into Site1.Web
My questions are:
What other options are there?
Which do you feel to be the most appropriate, usable & maintainable?
(The reason I'd like the resources in a single, separate project is to avoid having to constantly merge a master resources location into each of the consuming sites, and merging back from each fix we make.)
You can create a second Web.Resources project for the second site, but link the files from the first resource. I know this means that you have an extra project, but in a way it's good because you have abstract the resources, but still maintained a certain level of separation.
To link files go .... Add--> Existing Item --> Select file(s) --> Beside "Add" there is a down arrow --> Click "Add As Link".
Hope this helps.
Unfortunately, this is one place where VS seems to fall down - I've been struggling with a similar problem.
One option you can try is to keep your resources in a separate, source controlled directory, and have a pre-build step that makes sure that there's a current copy in a directory visible, but not part of, the solution.
There are lots of drawbacks to this - you'll probably get warnings about missing css classes, and I'm not sure if javascript intellisense will be enabled, so if you do find a resolution, make sure you update your question!

Resources