What Was I Thinking?

Follies & Foils of .NET Development

  Home  |   Contact  |   Syndication    |   Login
  74 Posts | 0 Stories | 191 Comments | 0 Trackbacks

News

Archives

Post Categories

Check These Out

Gurus

Saturday, January 30, 2010 #

In Visual Studio (2008) Web Site Projects do not support pre/post build events.  Web applications do, but web sites do not.

 

This doesn’t mean you can’t have pre/post build events however.  You just have to be a little creative.

 

In my scenario, I needed a pre-build event to fire. 

1. I added a new class library project to my solution and configured its post build event to execute the pre-build event I wanted. 

2. I added a project dependency on the Web Site of the new class library.

Right click the solution explorer on the solution node.

Select Project Dependencies.

Select the web site in the project list dropdown at the top of the dialog.

Check the new class library project on the list of available projects.

Close the dialog.

Now when my web site builds, it builds my new class library, which in turn executes its post-build event.  The result is custom logic executing before my web site is built.  SUCCESS!

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Recently I needed to determine the length of a string and perform a Substring operation on a variable in a DOS Batch (.bat) file.  (Yes, people still use DOS batch files!)

After some Googling and some playing around I came up with the following functions. 

 

:Substring
::Substring(retVal,string,startIndex,length)
:: extracts the substring from string starting at startIndex for the specified length 
 SET string=%2%
 SET startIndex=%3%
 SET length=%4%
 
 if "%4" == "0" goto :noLength
 CALL SET _substring=%%string:~%startIndex%,%length%%%
 goto :substringResult
 :noLength
 CALL SET _substring=%%string:~%startIndex%%%
 :substringResult
 set "%~1=%_substring%"
GOTO :EOF
 
:StrLength
::StrLength(retVal,string)
::returns the length of the string specified in %2 and stores it in %1
set #=%2%
set length=0
:stringLengthLoop
if defined # (set #=%#:~1%&set /A length += 1&goto stringLengthLoop)
::echo the string is %length% characters long!
set "%~1=%length%"
GOTO :EOF

 

To call them:

 

:: get the lenth of the sConfigFileRoot
call:StrLength length %sCFR%

:: extract the suffix
call:Substring suffix,%fileroot%,%length%,0

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati