OutDir vs OutputPath for Visual studio 2015 and Asp.Net Core


In MSBuild for Asp.Net Core use /p:OutputPath parameter, not /p:OutDir nor both.

Full story

We’ve used psake powershell build for ASP.Net 4.61 project and passed both parameters
msbuild  /p:OutDir=“$binariesDir\” /p:OutputPath=“$outPath\”
Actually /p:OutputPath was ignored(almost, see below) and build was saved to specified in /p:OutDir folder.
When I included Asp.Net Core project into solution, it’s failed because dll, referenced by the Core project, was saved to OutDir folder, but Asp.Net Core project tried to find it in OutputPath folder.
I’ve tried to remove /p:OutputPath  parameter (as suggested in OutputPath vs OutDir thread: “to keep the OutputPath that is generated by Visual Studio, then set the OutDir as a command argument”), Asp.Net Core project failed because dll was saved to OutDir folder, but Asp.Net Core project tried to find it in relative bin\Release\ folder.
When I removed OutDir parameter and specified /p:OutputPath=“$binariesDir\” build was successful,  but package for MSDeploy, specified in a custom MS Build step, was created in a relative path obj\Release\Package rather than specified $binariesDir folder, so I needed to adjust package path.
Current VS 2015 MSDN page  Common MSBuild Project Properties doesn’t document OutDir , but only OutputPath.
Note that previously MSDN recommended the opposite: “OutputPath has been deprecated and OutDir should be used instead whenever possible. ”

Write-Host And Write-Debug differently interpret double quotes

I have a string, that I wanted to output. I’ve tried Write-Debug and it caused error due to unescaped double quote.However when I used Write-Host, the same string was output successfully with unescaped double quotes just ignored.

$DebugPreference = “Continue”
Write-Host ” /cttDir=” \Base Config”  ”

Write-Debug ” /cttDir=” \Base Config”  ”

 /cttDir= \Base Config 

Write-Debug : A positional parameter cannot be found that accepts argument ‘\Base’.

At C:\Users\Temp\a15f78a2-cf2b-49b7-b6e7-bb7aef345639.ps1:3 char:1

+ Write-Debug ” /cttDir=”\Base Config”  ”

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Write-Debug], ParameterBindingException

    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.WriteDebugCommand.
For this purpose Write-Host is more convenient, but the right way to fix is to escape double quotes inside the string.

#powershell, #write-debug, #write-host

Powershell script that requires administrative privileges.

For Powershell it can be done easier
#from http://serverfault.com/a/12306/107224 
function Run-Elevated ($scriptblock )
  # TODO: make -NoExit a parameter
  # TODO: just open PS (no -Command parameter) if $scriptblock -eq ”
  $sh = new-object -com ‘Shell.Application’
  $sh. ShellExecute(‘powershell’, “-NoExit -Command $scriptblock , , ‘runas’)
Run-Elevated  “cd  $PSScriptRoot; ActualScript.ps1  ; Read-Host -Prompt `”Press_Enter_to_continue`”  ” 


Powershell ISE missing features

I’ve recently did some work with PowerShell ISE and missed a few features,that I wish to have in the ISE.
1.It will be good to Stop debugger(Shift-F5) icon on toolbar
2.In the popup
Windows PowerShell ISE
You cannot edit any script files in Windows PowerShell ISE while the debugger is running. To edit a script, stop the debugger.
it will be good to add button to stop debugger.
  1. When stopped at breakpoint, Run Script(F5) button is disabled, when it’s actually allowed.
  1. May be more complicate, but it will be nice to add an ability to change current position in debugger (Shift F10 in Visual Studio)
  2.  Find does the search only in only one direction; it should, if not found down, continue to search from the top.
  3. Ability to make block comments
Just before writing this post I found article about looking very useful add-on http://www.powershellmagazine.com/2014/03/28/isesteroids-a-revolutionary-powershell-ise-add-on/
but I didn’t have a chance to try it yet.

Batch file that required administrative privileges.

I wanted to call from batch file powershell script that required administrative privileges.
I needed to check, if it was started as Administrator and also set current directory where the batch is located.
Thanks to couple of stackoverflow questions I’ve got this batch
@echo off
goto check_Permissions
powershell &:: TODO the script to call
goto end
    net session >nul 2>&1
    if %errorLevel% == 0 (
        @rem echo Success: Administrative permissions confirmed.
          goto process
    ) else (
        echo Administrative permissions required.
    pause >nul

PowerShell function to delete if exist and create empty folder

In our PowerShell scripts for different folder it’s required to delete if exist and create empty folder. To avoid to repeat folder name in three commands I’ve created a function

function DeleteIfExistsAndCreateEmptyFolder($dir )
      if ( Test-Path $dir ) {
               Get-ChildItem -Path  $dir -Force -Recurse | Remove-Item -force -recurse
               Remove-Item $dir -Force


    New-Item -ItemType Directory -Force -Path $dir
I’ve also used this function in  answer for SuperUser question How can I copy a directory, overwriting its contents if it exists using Powershell?

Using CTT to modify config files for different environments

We previously tried to use msbuild to adjust configuration files for different environments.

Recently I found

onfig Transformation Tool(CTT) on CodePlex

and with

addition of global replace using powershell

it is enough and easier to do all required modifications

Content of ChangeConfig.cmd:

ctt s:..web.config t:WebConfig.CTT d:..web.config

powershell.exe -command “Get-Content ..Remoting.config | ForEach-Object { $_ -replace ‘//localhost/ServicesCI/’, ‘//ServerName01/ServicesCI/’ } | Set-Content ..remoting.temp”

powershell.exe -command “copy  ..remoting.temp ..remoting.config”

ctt s:..EnterpriseLibraryLogging.config t:EnterpriseLibraryLogging.CTT d:..EnterpriseLibraryLogging.config

@goto end

@rem some code that currently not used



Content of example




key=”ShowDeveloperExceptionInfo” value=”False” xdt:Transform=”Replace”  xdt:Locator=”Match(key)” />




name=”ServiceModelMessageLoggingListener” initializeData=”C:temptestCIcopy2.svclog”   xdt:Locator=”Match(name)” xdt:Transform=”SetAttributes(initializeData)”   />




Extract from web.config –
sharedListeners section


initializeData=”C:tempTEST.svclog” type=”System.Diagnostics.XmlWriterTraceListener, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089″ name=”ServiceModelMessageLoggingListener” traceOutputOptions=”Timestamp”>

type=”” />



Batch file to Delete Old Virtual Directories.

On some servers we have many old Virtual Directories created for previous versions of our application.
IIS user interface allows to delete only one in a time.
Fortunately we can use IIS scripts as described in

How to manage Web sites and Web virtual directories by using command-line scripts in IIS 6.0

I’ve created batch file DeleteOldVDirs.cmd

rem http://support.microsoft.com/kb/816568
rem syntax: iisvdir /delete WebSite [/Virtual Path]Name [/s Computer [/u [Domain]User /p Password]]

REM list all directories and create batch of deletes
iisvdir /query “Default Web Site”

echo “Enter Ctrl-C  if you want to stop deleting”
iisvdir /delete “Default Web Site/VDirName1”

iisvdir /delete “Default Web Site/VDirName2”

If the name of WebSite or Virtual directory contain spaces(e.g  “Default Web Site”), don’t forget to use double quotes.
Note that the batch doesn’t delete physical directories from flie system.You need to delete them using Windows Explorer, but it does support multiple selection!