Why is GetEnvironmentVariable() returning the wrong directory for my RoleRoot in Windows Azure? -
i trying create worker role project windows azure loads custom exe upon startup. adapted code david chou's jetty server example found here:
http://blogs.msdn.com/b/dachou/archive/2010/03/21/run-java-with-jetty-in-windows-azure.aspx
using visual web developer 2010, created new cloud project visual c# , dropped in worker role class code shown here:
namespace workerrole1 { public class workerrole : roleentrypoint { public override void run() { string response = ""; string s = ""; try { system.io.streamreader sr; string port = roleenvironment.currentroleinstance.instanceendpoints["httpin"].ipendpoint.port.tostring(); string roleroot = environment.getenvironmentvariable("roleroot"); s = "roleroot is: " + roleroot; trace.traceinformation(s); // string myazureapphome = roleroot + @"\approot\app"; string myazureapphome = system.io.path.combine(roleroot + @"\", @"approot\"); s = "myazureapphome is: " + myazureapphome; trace.traceinformation(s); // string jrehome = roleroot + @"\approot\app\jre6"; process proc = new process(); proc.startinfo.useshellexecute = false; proc.startinfo.redirectstandardoutput = true; //proc.startinfo.filename = string.format("\"{0}\\bin\\java.exe\"", jrehome); // proc.startinfo.arguments = string.format("-djetty.port={0} -djetty.home=\"{1}\" -jar \"{1}\\start.jar\"", port, myazureapphome); proc.startinfo.filename = string.format("\"{0}\\myazureappprj.exe\"", myazureapphome); s = "attempting run file: " + proc.startinfo.filename; trace.traceinformation(s); proc.enableraisingevents = false; proc.start(); sr = proc.standardoutput; response = sr.readtoend(); } catch (exception ex) { response = ex.message; trace.traceerror(response); } } public override bool onstart() { // set maximum number of concurrent connections servicepointmanager.defaultconnectionlimit = 12; // information on handling configuration changes // see msdn topic @ http://go.microsoft.com/fwlink/?linkid=166357. return base.onstart(); } } } the problem directory getting roleroot not match "app" support files showing when run project against storage emulator. "app" folder ends in directory found searching windowsazureproject2 directory tree:
c:\users\mycomp\documents\visual studio 2010\projects\windowsazureproject2\workerrole1\app
but getenvironmentvariable("roleroot") reports following roleroot directory dumped trace statement:
c:\users\mycomp\documents\visual studio 2010\projects\windowsazureproject2\windowsazureproject2\bin\debug\windowsazureproject2.csx\roles\workerrole1
which of course leads file not found exception when proc.start() called because custom exe file in former directory, , not latter.
can tell why roleroot path appears botched , can fix this? note, i'm aware of double backslash problem before exe in assignment proc.startinfo.filename (is visual web developer c# different visual studio pro c#?), fixing not change path problem having since directory being returned getenvironmentvariable("roleroot") flat out not contain "app" directory.
update: after doing more reading appears me what's happening "approot" directory not being created , "app" folder files not being copied on either. still can't figure out why.
-- roschler
looks didn't add files in app directory visual studio project. make sure they're added , have "copy output directory" property set "copy always" (or "copy if newer"). should end under %roleroot% expect.
Comments
Post a Comment