Publish a Web Application from the Command Line

后端 未结 4 1293
清酒与你
清酒与你 2020-12-24 14:14

I\'ve got a series of .NET 4 based web applications (WCF and Web) within the same solution, but need to selectively publish, from the command line.

I\'ve tried vario

4条回答
  •  攒了一身酷
    2020-12-24 15:14

    Save the following script as publishProject.bat

    rem publish passed project 
    rem params: %configuration% %destDir% %srcDir% %proj%
    @echo off
    SET DestPath=d:\projects\Publish\%2
    SET SrcPath=d:\projects\Src\%3\
    SET ProjectName=%4
    SET Configuration=%1
    
    RD /S /Q "%DestPath%" rem clear existed directory
    :: build project
    MSBuild  "%SrcPath%%ProjectName%.vbproj" /p:Configuration=%Configuration%
    :: deploy project
    ::/t:TransformWebConfig
    MSBuild "%SrcPath%%ProjectName%.vbproj" /target:_CopyWebApplication /property:OutDir=%DestPath%\ /property:WebProjectOutputDir=%DestPath% /p:Configuration=%Configuration%
    xcopy "%SrcPath%bin\*.*" "%DestPath%\bin\" /k /y
    
    echo =========================================
    echo %SrcPath%%3.vbproj is published
    echo =========================================
    

    I call it from another batch file

    @echo off
    rem VS2010. For VS2008 change %VS100COMNTOOLS% to %VS90COMNTOOLS%
    call "%VS100COMNTOOLS%\vsvars32.bat" 
    SET ex=.\publishProject.bat Release
    
    call %ex% KillerWebApp1 KillerWebApp1\KillerWebApp1 KillerWebApp1
    call %ex% KillerWebApp2 KillerWebApp2\KillerWebApp2 KillerWebApp2
    call %ex% KillerWebApp3 KillerWebApp3\KillerWebApp3 KillerWebApp3
    call %ex% KillerWebApp4 KillerWebApp4\KillerWebApp4 KillerWebApp4
    

    EDIT: Code above works for most cases but not for all. I.e. we use another asp .net application and link it as virtual folder in IIS. For this situation VS2008 worked fine with code above but VS2010 also copy files from virtual directory while deploying. The following code works properly also in VS2010 (solution was found here)

    Add to your project file (*.csproj, *.vbproj)

    
        
        
    
        
            
        
    
        
    
    

    Change publishProject.bat to:

    rem publish passed project 
    rem params: %configuration% %destDir% %srcDir% %proj%
    @echo off
    SET DestPath=d:\projects\Publish\%2
    SET SrcPath=d:\projects\Src\%3\
    SET ProjectName=%4
    SET Configuration=%1
    
    :: clear existed directory
    RD /S /Q "%DestPath%"
    
    :: build and publish project
    MSBuild "%SrcPath%%ProjectName%.vbproj" "/p:Configuration=%Configuration%;AutoParameterizationWebConfigConnectionStrings=False;PublishDestination=%DestPath%" /t:PublishToFileSystem
    

提交回复
热议问题