Infragistics NetAdvantage Vol.1在vs.net下的设置

刚刚接了一下公司内部的活儿,上一篇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),下面是宏的代码:

  1. Open Visual Studio .NET
  2. Open Macros Explorer window (Tools -> Macros Explorer)
  3. Right click MyMacros root node and select New Macro Project
  4. Open the Module within your new Macro project
  5. Open the EnvironmentEvents module
  6. Select BuildEvents from the Class Name drop down
  7. Select OnBuildBegin from the Event Name drop down
  8. 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

你可能感兴趣的:(.Net,&,C#,&,Web)