Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Website Reference Paths

In Visual Studio website projects (in Visual Studio 2005 or later, not web application projects where there is still a .csproj file) how is the reference information stored, and is it possible to source control it without storing compiled binaries in source control?

If you right-click on a website project and select Property Pages, the first screen (References) lists all the project references.

System.* references are listed as type GAC, and other DLL files can be listed as BIN or Project.

The problem occurs when you include something as a project reference, and then commit it to source control (for us, Subversion, ignoring .dll and .pdb files.)

Another developer gets updated code from the repository and has to manually set up all of these project references, but I can't even determine where this information is stored, unless it's in that .suo, which is NOT source-control friendly.

like image 347
David Boike Avatar asked Nov 10 '08 22:11

David Boike


People also ask

How do I add a reference path in Visual Studio?

If you're using Visual Basic, select the References page, and then click the Reference Paths button. In the Reference Paths dialog box, type the path of the folder that contains the item you want to reference in the Folder field, and then click the Add Folder button.

Where are Visual Studio references stored?

References are stored in the . csproj file.

How do I show references in Visual Studio?

Press Shift + F12 to find all references.


2 Answers

If you reference a .dll by file name through the browse tab, there should be a .refresh file created (nested under the dll in BIN). We put those in SVN and it works great (you may have to hand edit them to use relative paths).

References added from the .NET tab are added to web.config

Project references are stored in the solution (.sln) file. Open the .sln file and you'll see them listed:

Project("{xxxxxxx-7377-xxxx-xxxx-BC803B73C61A}") = "XXXXXXX.Web", "XXXXXXX.Web", "{xxxxxxxx-BB14-xxxx-B3B6-8BF6D8BC5AFF}"
    ProjectSection(WebsiteProperties) = preProject
        TargetFramework = "3.5"
        ProjectReferences = "{xxxxxxxx-C3AB-xxxx-BBED-2055287036E5}|XXXXXX.Data.dll;
            ...
like image 81
John Sheehan Avatar answered Oct 08 '22 03:10

John Sheehan


“Web Site” projects in Visual Studio are a strange thing. They seem to be an attempt to cater to traditional web developers, where a “site” is just a set of files in a directory. In much the same way, when you make a “Web Site” project in Visual Studio, there is no real “project” file, like C# projects have a .csproj file. However, there is still a solution file (.sln). Normally, assembly .dll references are saved in the project file. Since a Web Site doesn’t have one, where do they go?

References to other projects

If you add a reference to another project, then an entry is made in the solution .sln file. It ends up looking like this:

Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "WebSite1", "..\..\WebSites\WebSite1\", "{F25DB9D6-810D-4C18-ACBB-BFC420D33B20}"
ProjectSection(WebsiteProperties) = preProject
TargetFramework = "3.5"
ProjectReferences = "{11666201-E9E8-4F5A-A7AB-93D90F3AD9DC}|ClassLibrary1.dll;"

File System References

If you browse the file system and add a .dll file, then Visual Studio will create a “.refresh” file with the same name in the \Bin folder. This file is just a 1-line text file that indicates the path that the file was loaded from. So for example if I added “MyAssem.dll” from ....\libs, then in the Web Site \Bin folder, I would end up with 2 files copied there: MyAssem.dll and MyAssem.dll.refresh. The .refresh file would contain the text: “....\libs”. At each build, Visual Studio will check the path in the .refresh file, and if a newer .dll exists there, it will overwrite the one in the Bin directory.

Warning: Visual Studio will NOT throw an error if the file does not exist where the .refresh file tells it to look. It will just continue to use the .dll already in the \Bin folder. It will however output a Warning.

GAC References

If you add an assembly from the Global Assembly Cache, Visual Studio will enter it in the Web.config file, like this:

<compilation debug="false">
 <assemblies>
  <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

Again the thing you have to watch for here is that Visual Studio assumes that if the assembly was in the GAC on your development computer, then it will be in the same place at runtime! That can get you into trouble if you maybe have Oracle.DataAccess installed on your dev machine, which would put it in the GAC, but when you deploy, you just copy the .dll into place on the production machine. It will still try to find it int he GAC and may fail at runtime.

I hope this helps clear up the oddities areund Web Sites and how references work!

like image 30
CodingWithSpike Avatar answered Oct 08 '22 03:10

CodingWithSpike