如何使用 GAC 程序集作为 csc.exe 的引用?

发布于 2024-07-21 05:41:17 字数 311 浏览 2 评论 0原文

我从 csc.exe 进行编译(嗯,CruiseControl 是...),并且我需要引用 GAC 中的 DLL。 我没有这个 DLL 作为简单文件的正确版本,但 GAC 中有正确的版本。

但是,您无法使用 csc 引用 GAC 中的程序集 - 您必须拥有实际文件的路径。

我发现一些参考资料声称您可以对实际文件的路径进行逆向工程,但我无法让它们发挥作用。 我启动了 Fusion 日志记录,并且可以看到运行时从何处获取文件,但在我的引用中使用该位置的文件路径不起作用。

那么,如何向 csc 提供对仅存在于 GAC 中的程序集版本的引用?

I'm compiling from csc.exe (well, CruiseControl is...), and I need to reference a DLL in the GAC. I do not have the correct version of this DLL as a simple file, but there is a correct version in the GAC.

However, you can't reference assemblies in the GAC with csc -- you have to have the path to the actual file.

I've found some references that claim you can reverse engineer the path to the actual file, but I haven't been able to get them work. I fired up Fusion logging, and I can see where the runtime is getting the file from, but using a filepath to that location in my reference does not work.

So, how do you provide csc with a reference to an assembly version that only exists in the GAC?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无人接听 2024-07-28 05:41:17

我有类似的问题。 我使用的解决方案是打开命令提示符并将目录更改为如下所示(根据您想要的程序集进行更改):

C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\3.5.0.0__31bf3856ad364e35\

然后您可以将此目录中的 DLL 复制到 GAC 之外的某个位置。

I had a similar problem. The solution I used was to open a command prompt and change directory to something like the following (change it depending on which assembly you want):

C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\3.5.0.0__31bf3856ad364e35\

You can then copy the DLL in this directory somewhere outside the GAC.

°如果伤别离去 2024-07-28 05:41:17

我建议使用 Nant 或 MSBuild,并仅使用 Visual Studio 生成的 .csproj 文件。 然后只需让 CruiseControl 使用您的 Nant 脚本即可。 以下是我编写的 Nant 脚本的摘录

<csc target="library" output="${basedir}/bin/${basename}.dll" debug="${debug}" optimize="true">
  <sources>
    <include name="src/app/**/*.cs"/>
  </sources>
  <references refid="My.Assemblies" />
</csc>

以及参考文献

      <assemblyfileset id="My.Assemblies"><include name="System.dll"></include>
    <include name="System.Configuration.dll"></include>
    <include name="System.Core.dll"></include>
    <include name="System.Data.dll"></include>
    <include name="System.Data.DataSetExtensions.dll"></include>
    <include name="System.Drawing.dll"></include>
    <include name="System.EnterpriseServices.dll"></include>
    <include name="System.Web.dll"></include>
    <include name="System.Web.Extensions.dll"></include>
    <include name="System.Web.Mobile.dll"></include>
    <include name="System.Web.Services.dll"></include>
    <include name="System.Xml.dll"></include>
    <include name="System.Linq.dll"></include>
</assemblyfileset>

I'd recommend using Nant or MSBuild and just use the .csproj file generated by visual studio. Then simply get CruiseControl to use your Nant script. Below is an extract from a Nant script I wrote,

<csc target="library" output="${basedir}/bin/${basename}.dll" debug="${debug}" optimize="true">
  <sources>
    <include name="src/app/**/*.cs"/>
  </sources>
  <references refid="My.Assemblies" />
</csc>

and the references

      <assemblyfileset id="My.Assemblies"><include name="System.dll"></include>
    <include name="System.Configuration.dll"></include>
    <include name="System.Core.dll"></include>
    <include name="System.Data.dll"></include>
    <include name="System.Data.DataSetExtensions.dll"></include>
    <include name="System.Drawing.dll"></include>
    <include name="System.EnterpriseServices.dll"></include>
    <include name="System.Web.dll"></include>
    <include name="System.Web.Extensions.dll"></include>
    <include name="System.Web.Mobile.dll"></include>
    <include name="System.Web.Services.dll"></include>
    <include name="System.Xml.dll"></include>
    <include name="System.Linq.dll"></include>
</assemblyfileset>
空宴 2024-07-28 05:41:17

当我针对 Excel PIA 进行编译时,我使用此路径在命令行上指定 csc.exe 的引用:
C:\windows\ assembly\GAC\Microsoft.Office.Interop.Excel\11.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll

编译成功。

??
这对你不起作用吗?

When I compiled against the Excel PIA's, I used this path to specify a reference on the command line for csc.exe:
C:\windows\assembly\GAC\Microsoft.Office.Interop.Excel\11.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll

The compile succeeded.

??
Does this not work for you?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文