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

Thursday, January 28, 2010 #

If you want to run a batch (.bat) file from within Visual Studio, you need to add an external tool.

 

From the Tools menu select External Tools, and then click Add.

Fill out the values as illustrated below:

AddExternalTool AddExternalTool

 

Click OK to close the dialog.

 

Now you can select the bat file to run in solution explorer, and select the Run Batch File command from the Tools menu.  The output of the batch file will be echoed to the output window inside visual studio.

 

<Revised 6/2/10>

You can also run .bat files from the solution explorer directly by associating the default behavior of “.BAT” extensions to Powershell.

 

  1. Right click the batch file in the Solution Explorer
  2. Select “Open With…”  from the context menu
  3. Click “Add…”
  4. In the “Program name” textbox , specify the full path of PowerShell (“\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”)
  5. In the “Friendly name” textbox enter “PowerShell”
  6. Select “Set As Default”
  7. Click OK

Now when you double click your batch file in the solution explorer, it will shell out to powershell and execute.

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

My unit test project uses a app.config file that has external source references to other config files located in my “configuration” folder.  My configuration folder is a sub folder of the unit test project.  When the unit test runs, I need to deploy this folder to the TestResults/Out folder so the app.config can be properly loaded during test execution.

 

Here’s the easiest way to accomplish deploying folders to the TestResults folder:

 

  1. Right click on the .testrunconfig file in your solution explorer.  For me, its LocalTestRun.testrunconfig.
  2. Select Open With and select XML editor
  3. Add a deployment item, specifying the relative path as the file name and an outputdirectory value of the directory name.  In my example, I want to deploy everything in the configuration directory to a folder called configuration in the testrun folder, so I’ve added the following entry:

<Deployment>
  <
DeploymentItem filename="Services\Identity\Claim\ClaimService.Test\configuration\" outputDirectory="configuration\" />
</
Deployment>

Now when my tests execution, Visual Studio copies over all my configuration file entries and is able to load the app.config file successfully.

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