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

TL;DR

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”  ”

Output:
 /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-batch

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.
—————————
OK  
—————————
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
:process
powershell &:: TODO the script to call
@pause
goto end
:check_Permissions
    net session >nul 2>&1
    if %errorLevel% == 0 (
        @rem echo Success: Administrative permissions confirmed.
          goto process
    ) else (
        echo Administrative permissions required.
    )
    pause >nul
:end

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

C
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

:End

@pause







Content of example
WebConfig.CTT
:




<?
xml
version=”1.0″?>
<

configuration
xmlns:xdt=”http://schemas.microsoft.com/XML-Document-Transform”>
<

appSettings
>
<

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

appSettings
>
<

system.diagnostics
>
<

sharedListeners
>
<

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

sharedListeners
>
</

system.diagnostics
>
</

configuration
>




Extract from web.config –
sharedListeners section






 <
sharedListeners
>
       <

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

filter
type=”” />

     </
add
>
   </

sharedListeners
>v