auto build nmake

open vs console then run command in it

store command in bat file,

this is not pwsh

this is not pwsh

this is not pwsh

generate nmake

cmd /D /K "Call "C:\Program Files (x86)\Microsoft Visual Studio\xxxx\Community\VC\Auxiliary\Build\vcvars64.bat" && cmake \abs\path\to\build -DCMAKE_BUILD_TYPE=Debug -G "NMake Makefiles" && exit"

build nmake

cd \abs\path\to\build && cmd /D /K "Call "C:\Program Files (x86)\Microsoft Visual Studio\xxxx\Community\VC\Auxiliary\Build\vcvars64.bat" && nmake /nologo -f Makefile && exit"
cmd /D /K "Call "C:\Program Files (x86)\Microsoft Visual Studio\xxxx\Community\VC\Auxiliary\Build\vcvars64.bat" &&  MSBuild -noLogo  YOUR.sln  /t:YOURProj /p:Configuration=Debug /p:Platform=x64 & exit /b"
    Using multiple commands and conditional processing symbols

    You can run multiple commands from a single command line or 
    script using conditional processing symbols. 
    When you run multiple commands with conditional processing symbols, 
    the commands to the right of the conditional processing symbol act based upon
    the results of the command to the left of the conditional processing symbol.

    For example, you might want to run a command only if the previous command fails.
    Or, you might want to run a command only if the previous command is successful.

    You can use the special characters listed in the following table to pass multiple commands.

        & [...]
        command1 & command2
        Use to separate multiple commands on one command line. 
        Cmd.exe runs the first command, and then the second command.

        && [...]
        command1 && command2
        Use to run the command following && only if the command preceding the symbol is successful. 
        Cmd.exe runs the first command, and then runs the second command
        only if the first command completed successfully.

        || [...]
        command1 || command2
        Use to run the command following || only if the command preceding || fails. 
        Cmd.exe runs the first command, and then runs the second command 
        only if the first command did not complete successfully (receives an error code greater than zero).

        ( ) [...]
        (command1 & command2)
        Use to group or nest multiple commands.

        ; or ,
        command1 parameter1;parameter2
        Use to separate command parameters.

https://stackoverflow.com/questions/8055371/how-do-i-run-two-commands-in-one-line-in-windows-cmd

So given a solution file mysolution.sln with projects:

    foo.vcxproj
    bar.vcxproj
    baz.vcxproj

where they all depend on each other in bottom to top order.
So that baz is most independent, bar depends on baz and foo depends on bar.

If you want to build foo then you do:

MSBuild mysolution.sln /target:foo

The other answers here didn't account about dependencies.
Sure msbuild.exe will build a single project file (i.e. foo.vcxproj),
but it would fail if bar and baz were not built yet.
In order to build multiple projects and get the independent projects built
first you have to pass in the solution file (After all the OP did mention this was part of a solution file).
Then pass in the project name and a target delimited by a colon.

MSBuild mysolution.sln /target:foo:Rebuild


msbuild test.sln /t:project;project2 /p:Configuration="Release" /p:Platform="x86" /p:BuildProjectReferences=false
To rebuild or clean, change /t:project to /t:project:clean or /t:project:rebuild
posted @ 2023-03-08 11:13  fndefbwefsowpvqfx  阅读(16)  评论(0编辑  收藏  举报