Visual Studio Website Reference Paths

2019-01-22 21:17发布

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.

3条回答
来,给爷笑一个
2楼-- · 2019-01-22 21:36

“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!

查看更多
我命由我不由天
3楼-- · 2019-01-22 21:41

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;
            ...
查看更多
Juvenile、少年°
4楼-- · 2019-01-22 21:41

I use copyprojectDll.ps1 powershell.

My folder structure is below

  • ClassLibraries
    ThirdParty
    Website/Bin
    CopyprojectDll.ps1
    Website.sln

ClassLibraries are code classes for my project, DAL .. Website project includes only web files, aspx, aspx.cs .. ThirdParty are required libraries, AjaxToolkit etc.

I compile ClassLibraries.sln I run CopyprojectDll.ps1 I use Website.sln after this.

Sample powershell file is below.

$folders = @(); $folders +="IB.Security" $folders +="ClassLibraries/Core.Classes"

function CopyDllsToWebBin($dll_files) { if ($dll_files -eq $null) { return; } $targetfolder = "./Kod/bin/"

foreach($dll in $dll_files)
{

    copy-item $dll.FullName -destination "$targetfolder" -force #-Verbose
}

}

function CopyDllsToThirdParty($dll_files) {

$targetfolder = "./ThirdParty/"

foreach($dll in $dll_files)
{
    copy-item $dll.FullName -destination "$targetfolder" -force #-Verbose
}

}

$dll_output_folder = "/bin/debug";

foreach($folder in $folders) { $dll_files = Get-ChildItem -Path $folder$dll_output_folder -include *.dll -Recurse | sort-object Name CopyDllsToWebBin($dll_files) $dll_files = Get-ChildItem -Path $folder$dll_output_folder -include *.pdb -Recurse | sort-object Name CopyDllsToWebBin($dll_files) $dll_files = Get-ChildItem -Path $folder$dll_output_folder -include *.xml -Recurse | sort-object Name CopyDllsToWebBin($dll_files) "Copied $folder$dll_output_folder"

}

$dll_files = Get-ChildItem -Path "ThirdParty" -include *.dll -Recurse | sort-object Name CopyDllsToWebBin($dll_files) $dll_files = Get-ChildItem -Path "ThirdParty" -include *.pdb -Recurse | sort-object Name CopyDllsToWebBin($dll_files) $dll_files = Get-ChildItem -Path $folder$dll_output_folder -include *.xml -Recurse | sort-object Name CopyDllsToWebBin($dll_files)

"Copied ThirdParty"

date

查看更多
登录 后发表回答