4

We have a project with included win32 dll as content file. This file (native32.dll) is copied to the output directory and imported at runtime. Visual studio compiles project without any problems, however TeamCity takes this .dll file (or any .dll file included in the project structure) and treats it as if it was a reference:

  csc.exe <..> /reference:native32.dll <..>

Build fails with error:

CSC error CS0009: Metadata file 'native32.dll' could not be opened -- PE image doesn't contain managed metadata

How can this native32.dll be excluded from being referenced?

Gabriel Davidian
  • 318
  • 2
  • 12

1 Answers1

1

You need to create a Class Library and include the DLL in that library, together with the wrapper/interop classes. Then just reference the class library from your other project that wouldn't compile before.

Filip Ekberg
  • 36,033
  • 20
  • 126
  • 183
  • 1
    Well, this seems like a TeamCity limitation hack, which is not the best way to fix issues like that - changes in project to cater to the build server, I hoped that this could be done in a direct way using configuration, but if there is no other way, I guess this is it. Marking as an answer. – Gabriel Davidian Jan 06 '16 at 11:40
  • I think it's an MSBuild limitation, the fact that it works in Visual Studio might just indicate that they do a bunch of magic for you that they really shouldn't. I don't have any evidence to prove that though. – Filip Ekberg Jan 07 '16 at 04:37
  • 1
    No - TeamCity specifically adds parameter to csc.exe command line at the build time, VS just does not adds /reference parameter to libraries that are not referenced in the project. At least I assume that csc command line is generated by TeamCity not MSBuild (this is how it should be anyway). – Gabriel Davidian Jan 07 '16 at 09:24
  • Interesting. Maybe a bug in TeamCity then? – Filip Ekberg Jan 08 '16 at 04:28
  • Since I did not receive any other answer how to do it using only TeamCity (and after checking all possible options in TeamCity) I assume that this indeed is either a bug or missing feature (to ignore included libraries from being referenced). Also it has started happening after upgrading to TeamCity 9 from 8, but I had to check if I indeed did everything correct and not missing something. – Gabriel Davidian Jan 08 '16 at 07:54
  • When I faced the same issue, I stumbled upon an old forum thread somewhere (I can't find it now) that had the same issue in a different context (not TeamCity). The recommended solution was to do a Class Library and it worked, I assumed that Visual Studio did some magic if you had this directly in your project and not in a class library. Interesting though. – Filip Ekberg Jan 11 '16 at 00:10