刚刚接了一下公司内部的活儿,上一篇blog已经说过了,项目中使用了Infragistics NetAdvantage Vol.1的控件。在vs.net下进行开发时,发现每次都提示 Infragistics.WebUI.Shared.dll
找不到,然后就手动将Copy Local设置成True。
之前一直没有找为什么会这样,又不想张嘴就问同事,于是翻了一下帮助,Introduction/Setting Up Your Development Enviroment/ASP.NET: Setting CopyLocal To True中对该问题进行了说明,以下是为什么要这样做的原因:
The shared assembly is registered into the Global Assembly Cache by the Windows Forms products, but Web Applications, by default, do not look in the GAC to resolve assembly references at runtime. Therefore, the Infragistics.WebUI.Shared assembly must be copied to the local project directory along with the respective Web element's assembly in order to run the Web application under IIS.
提供了两种解决方法,一种是手动设置,一种是使用vs.net提供的宏(Macro),下面是宏的代码:
- Open Visual Studio .NET
- Open Macros Explorer window (Tools -> Macros Explorer)
- Right click MyMacros root node and select New Macro Project
- Open the Module within your new Macro project
- Open the EnvironmentEvents module
- Select BuildEvents from the Class Name drop down
- Select OnBuildBegin from the Event Name drop down
- Implement the OnBuildBegin event handler:
Private Sub BuildEvents_OnBuildBegin(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildBegin
Dim s As Solution
Dim p As Project
Dim vs As VSProject
Dim r As Reference
s = DTE.Solution
For Each p In s.Projects
vs = p.Object
For Each r In vs.References
If Regex.IsMatch(r.Identity, "^Infragistics/.WebUI/.Shared.*") Then
r.CopyLocal = True
Exit For
End If
Next
Next
End Sub
只使用以上代码也是不好用的,还要导入以下两个命名空间:
Imports VSLangProj
Imports System.Text.RegularExpressions