Deane
Deane

Reputation: 8747

How do you use GAC'd assemblies as references with csc.exe?

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?

Upvotes: 5

Views: 5052

Answers (3)

danswain
danswain

Reputation: 4177

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>

Upvotes: 4

Luke Woodward
Luke Woodward

Reputation: 64959

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.

Upvotes: 4

Cheeso
Cheeso

Reputation: 192487

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?

Upvotes: 0

Related Questions