tags:

views:

1018

answers:

3

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?

A: 

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?

Cheeso
I think it was your Web site where I read about this, because the Office Interop stuff was used as an example.But, no -- this didn't work. I looked at the Fusion log, and mine wass a little different: it was "GAC_MSIL" rather than just "GAC". But, neither path worked, at any rate.
Deane
That is disappointing. re: "neither path worked." Well, only one path is the right path. Have you verified that the DLL actually exists at that path? It would require a command line, I guess. You'd have to CD into the Microsoft.Office.Interop.Excel directory and then find the rest of the path including all those numbers, which I Think vary by release and machine. Once you verify the path, can you retry with csc.exe /r:<foo> ?
Cheeso
+2  A: 

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.

Pourquoi Litytestdata
Yes, that was the key -- I had to navigate to that folder at a command prompt, then *copy the DLL out to somewhere else*. You can't put that folder path in a CSC task in CruiseControl for some reason. But if you copy the DLL out (and change permissions), you can reference it just fine.
Deane
A: 

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>
danswain
I don't like doing this because, with multiple developers, you start running into proj file concurrency issues. Each developer has their own proj file, and you get situations where they're different, and SVN screws them up when it merges, and other weirdness. I would prefer to just compile all source files with csc.
Deane
I respectfully disagree, dealing with merge issues seems easier than copying files out the GAC and playing with permissions. After all how is it different from merging source files. We now use MSBuild at work and work in teams of 10 or so and proj files whilst annoying aren't that much of an issue.
danswain