For Programmers: Free Programming Magazines  


Home > Archive > C# > December 2005 > Can Build be instructed to copy source files.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Can Build be instructed to copy source files.
News@InsightfulMES.com

2005-12-09, 7:17 pm

I have written a couple class library projects that get compiled into
DLLs. The logic references some XML and SQL Script source files. The
data in these files integral to the DLL but doesn't get compiled into
it.

In my development environment project I created two new folders to hold
these files.

When I build the installation kit I can instruct it to pull these two
directories. When I install the the kit the DLL goes into the new
target folder and the two folder with the files are created in this
same folder.

I'd like to write and test my code to look for these files using a
relative path. In otherwords something like "Current App Path" +
"/XML/somefile.xml". But during development this doesn't work because
the DLL is down in ../bin/debug and the SQL and XML folder are relative
to the source code (ie. the .cs files).

So I guess my question is this - Is there a way to instruct the
compiler to copy these two folders into the same folder as the DLL file
that is generated? If so then I could debug using the same logic that
will work when put into production.

Or maybe there is another way to specify a relative path that will work
in development and in production.

Mike Buchanan

Stoofer

2005-12-11, 7:14 pm

In the properties for a project you can specify a post build step. You
could use this to copy the files to the build area. There is a
$TargetPath macro which make this a doddle.

If the files are integral to the dll you could also consider building
them as embedded resource, which would place the files inside your dll.
You can then get at them using the manifest resource stream.

News@InsightfulMES.com

2005-12-12, 10:10 pm

Stoofer,

OK. I tried this and it seems to work. I added this Post-Build script
:

xcopy/E/I $(ProjectDir)SQL $(TargetDir)SQL
xcopy/E/I $(ProjectDir)TxnXML $(TargetDir)TxnXML

=====

Could you provide an example, or point me to a reference, that would
show how to use the "embedded resource" option?

Mike Buchanan

Stoofer

2005-12-13, 8:14 am

First, you need to select your xml file properties and change the build
action to "Embedded Resource". Then, to access the file from the
application use something like:

//This assumes that the class accessing the resource is in the same
assembly as the file
Assembly myAssembly = GetType().Assembly;

//Note that the filename's relative folders are treated as dotted
filename portions
String filename = "relative.folder.path.myxmlfile.xml";

using( System.IO.Stream resStream =
myAssembly.GetManifestResourceStream(filename))
{
//Do what you need to do with the file stream here - e.g. attach
XML stream readers
}

Hope this helps!

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com