Build Visual Studio project through the command line

后端 未结 4 706
故里飘歌
故里飘歌 2020-11-30 01:51

I am running an ASP.NET website from a Windows Server 2008 installation, and I like to edit the pages through the command line since I ssh into the server.

I install

相关标签:
4条回答
  • 2020-11-30 02:28

    Create a .bat file called: Manual_MSBuild_ReleaseVersion.bat

    Put this in the .bat file.

    REM you'll have to find the "latest" version of where msbuild.exe resides on your machine.. here are some popular versions/locations
    REM set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v2.0.50727
    REM set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v3.5
    REM set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v4.0.30319
    REM set msBuildDir=C:\Program Files (x86)\MSBuild\12.0\Bin
    set msBuildDir=C:\Program Files (x86)\MSBuild\14.0\Bin
    
    call "%msBuildDir%\msbuild.exe"  MySolution.sln /p:Configuration=Release /l:FileLogger,Microsoft.Build.Engine;logfile=Manual_MSBuild_ReleaseVersion_LOG.log
    set msBuildDir=
    

    You can build a .sln file or a .csproj file. MySolution.sln or MyProject.csproj

    See How to: Use MSBuild to Create a Web Package for more information.

    You can take it one step further:

    rd .\BuildResults /S /Q
    md .\BuildResults
    rd .\MyProject\Bin\Release  /S /Q
    
    REM you'll have to find the "latest" version of where msbuild.exe resides on your machine.. here are some popular versions/locations
    REM set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v2.0.50727
    REM set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v3.5
    REM set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v4.0.30319
    REM set msBuildDir=C:\Program Files (x86)\MSBuild\12.0\Bin
    set msBuildDir=C:\Program Files (x86)\MSBuild\14.0\Bin
    call "%msBuildDir%\msbuild.exe"  MySolution.sln /p:Configuration=Release /l:FileLogger,Microsoft.Build.Engine;logfile=Manual_MSBuild_ReleaseVersion_LOG.log
    set msBuildDir=
    
    XCOPY .\MyProject\Bin\Release\*.* .\BuildResults\
    

    That way, you remove a directory (just to make sure you get a super clean build), create it, build the solution/project and then copy the results of the build to the fresh directory.

    Super fresh, every time. And if the build blows up, the \BuildResults directory is empty.

    And a subtle little indicator, the datetime of the \BuildResults directory is the last time you built (or tried to build) the solution/project. Subtle, but sometimes helpful.

    0 讨论(0)
  • 2020-11-30 02:34

    I used a modification of the answer by @granadaCoder above.

    For .NET version 4.5 onwards, there is no corresponding build directory in

    %WINDIR%\Microsoft.NET\Framework\

    and using MSBuild for an older framework will not let you compile newer constructs like interpolated strings.

    TO get around this, you'll need to install the latest MS Build Tools (2015 currently) and use MSBuild.exe in

    %programfiles(x86)%\MSBuild\14.0\Bin

    0 讨论(0)
  • 2020-11-30 02:36

    Maybe with this command:

      >> devenv myproject.sln /Build "Release|x86"
    

    You can find devenv in "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" path.

    0 讨论(0)
  • 2020-11-30 02:36

    Install the .NET SDK and use the MsBuild.exe command line tool. It's what Visual Studio uses when you build a project or solution.

    0 讨论(0)
提交回复
热议问题