Monday, August 22, 2005

Adding an Embedded Resource to a csc command line compiled assembly

While using Rake to compile and execute NanoContainer.Tests, 4 of my tests kept failing. They were relying on 4 embedded resources that I was not embedding. In Visual Studio it's easy to embed a resource. DevHood and CodeProject both give good information on embedding using Visual Studio.net; however, I wanted to embed a resource using the command line.

MSDN2 provided some good info specific to the command line, but everything I found seemed to detail how to add a .resources or .resx file to an assembly. I needed to add .cs, .js, .java, and .vb files to the assembly. Using csc -? and resgen -? didn't seem to lead me in the right direction either.

Finally I gave up on finding the documentation I needed and starting shooting in the dark. I used /res, /win32res, and /linkresource. The tests kept failing. /res seemed like the answer, but the documentation focuses on .resources files so there was no way to be sure. Enter James Johnson's demo executable. I'd done everything I could think of and the tests were still failing. It was time to fire up an app that could show me what resources were contained in my assembly.

It turned out that my assembly was embedding the resource correctly when I used /res; however, an identifier needed to be given to match the identifier specified in the NanoContainer tests. Once I added the identifier all the tests passed.

Final correct csc (broken to multiple lines for readablity):
csc /out:../build/NanoContainer.Tests.dll /res:'TestScripts/test.cs,NanoContainer.Tests.TestScripts.test.cs' /res:'TestScripts/test.js,NanoContainer.Tests.TestScripts.test.js' /res:'TestScripts/test.java,NanoContainer.Tests.TestScripts.test.java' /res:'TestScripts/test.vb,NanoContainer.Tests.TestScripts.test.vb' /target:library /recurse:*.cs /lib:'../build' /r:'PicoContainer.dll;Microsoft.JScript.dll;VJSharpCodeProvider.dll;Castle.DynamicProxy.dll;NanoContainer.dll;NMock.dll;NUnit.Framework.dll'

2 comments:

  1. Isn't there an equivalent to the "solution" task in NAnt for Rake? I don't see how it would be better if I had to manually specify things like including resource files in the build script.

    How mature is Pico/Nano for .Net these days? Is it in active development?

    ReplyDelete
  2. I doubt there is a solution task in rake since I've never seen anyone using rake for .net projects. There are surely trade-offs for using rake. As Sam already pointed out previously, it requires developers to install Ruby and rake. Also, your csc task must be maintained in parallel with the solution changes. However, I believe it maybe worth the trouble to get the benefits that rake brings. The largest benefits to using rake are improved readability & performance. I'm honestly not prepared to agrue for or against the idea until I try it on a project though.

    Pico/Nano (.net) have done everything I've needed when I used them. My last project made fairly extensive use of Pico actually. Of course, Mike Ward (the primary contributor to both) was on my team so that was highly helpful. I recommend using it based on my previous experience.

    ReplyDelete

Note: Only a member of this blog may post a comment.