Commandline Build importing Environment Variables

H

Ha

Is there a way for me to use an environment variable when specifying
the output directory?
For example if I have SPCHOME set to "C:\spcroot\spc"
I want the output directory to be ${SPCHOME}\bin

Is there a way to pass in a flag to devenv such that the compiler can
resolve ${SPCHOME}?

In the VC++ days the /useenv flag was possible. How do I do this with
a C# project?

Thanks,
Ha
 
W

William Stacey [MVP]

Not sure about from IDE. If not, I might create a CMD file instead and call
that from IDE. You can still pass any IDE vars into your cmd file as
arguments. Then in your cmd file, you can get command line args (i.e. %1
%2, etc) and environment vars as normal.
 
W

William Stacey [MVP]

Just remembered something. The lines in your post/pre are actually used to
dynamically build a .bat file that is run for your build event. You will
see it in ..\bin\release\Postbuildevent.bat for example. As a bat file, you
can refer to any env you have using normal bat file constructs like
%mydir%\abc.txt such as:

Example lines in my postbuildevent.
cd "$(ProjectDir)"
copy "$(ProjectDir)..\netdig\bin\release\netdig.exe"
"$(TargetDir)NetDig.com"
cmd /c "$(ProjectDir)\MakeXeno.bat"
echo %SystemDrive%

Is converted to this batch file and run by the IDE:

@echo off
cd "C:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\NetDigWin\"
copy "C:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\NetDigWin\..\netdig\bin\release\netdig.exe" "C:\Documents and
Settings\Administrator\My Documents\Visual Studio
Projects\NetDigWin\bin\Release\NetDig.com"
cmd /c "C:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\NetDigWin\\MakeXeno.bat"
echo %SystemDrive%
if errorlevel 1 goto CSharpReportError
goto CSharpEnd
:CSharpReportError
echo Project error: A tool returned an error code from the build event
exit 1
:CSharpEnd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top