El TecnoBaúl de Kiquenet

Kiquenet boring stories

Open WebServer for SVC (WCF Host) in development

Posted by kiquenet en 9 octubre 2014

From Visual Studio, open WebServer with View in Browser (about svc file):

Using Process Monitor, I get full command line:

"C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\11.0\WebDev.WebServer40.exe" /port:9195 /path:"C:\TFS\VSIntegration\VSIntegration.SvcDespliegue.Host" /vpath:"/"

Scripting

@echo off
SET WEBDEV40="%ProgramFiles(x86)%\Common Files\Microsoft Shared\DevServer\11.0\"
SET WEBSERVER40="WebDev.WebServer40.exe"
START /D %WEBDEV40% /B WebDev.WebServer40.exe /port:9195 /path:"C:\TFS\VSIntegration\VSIntegration.SvcDespliegue.Host" /vpath:"/"
SET mypath=%~dp0

REM Error: WebServer crash when I call Svc ¿? Maybe relative path
REM START /D %WEBDEV40% /B WebDev.WebServer40.exe /port:9195 /path:"%mypath%..\..\VSIntegration\VSIntegration.SvcDeployment.Host"

Powershell

function Start-Webserver
{
    PARAM
    (
        [ValidateNotNull()]
        [int]$port = 8080,

        [ValidateNotNullOrEmpty()]
        [ValidateScript({Test-Path $_})]
        [string]$path = (pwd)
    )

    Set-Variable PROCESSDIRECTORY -Option Constant -value ([System.Environment]::ExpandEnvironmentVariables('%CommonProgramFiles(x86)%\Microsoft Shared\DevServer\11.0\'))
    Set-Variable PROCESSNAME -Option Constant -value 'WebDev.WebServer40.exe'

    $matchingProcesses = Get-WmiObject Win32_Process -Filter " name = '$PROCESSNAME' " |
        Where-Object { $_.CommandLine -like "*/port:$port*" }

    if($matchingProcesses -ne $null)
    {
        # output a warning if another path than given path is used by existing process
        if(-not($matchingProcesses.CommandLine -like "*/port:$port /path:$path"))
        {
            Write-Warning ('Process "{0}" with PID "{1}" already listening to port "{2}"
CommandLine: "{3}"' -f $matchingProcesses.Name, $matchingProcesses.Handle, $port, $matchingProcesses.CommandLine)
        }
        return
    }

    & "$PROCESSDIRECTORY$PROCESSNAME" /port:$port /path:$path
    & start http://localhost:$port/
}

Sources:
http://learningpcs.blogspot.com.es/2011/08/utility-webdevwebserverexe.html
http://blog.gehtnicht.at/p/2014/06/24/start-webdev-webserver40-exe-with-powershell/

Anuncios

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

 
A %d blogueros les gusta esto: