I'm working on a batch script that will build projects made with Visual Studio 2010. I need it to build four variations of the same project: 32-bit Debug, 32-bit Release, 64-bit Debug, and 64-bit Release.
So far, I think I've figured out how to build the project with it's last saved settings:
"%MSBUILD_DIR%\MSBuild.exe" !PROJECTNAME!.vcxproj /t:Build^
How can I modify this, so that it will build the four different configurations that I need?
#echo off
setlocal
set _project=project.vcxproj
call :do_build "%_project%" Release Win32
call :do_build "%_project%" Debug Win32
call :do_build "%_project%" Release x64
call :do_build "%_project%" Debug x64
endlocal
exit /b 0
:do_build
setlocal
set _proj=%~1
set _conf=%~2
set _arch=%~3
set _code=0
if "%_arch%"=="Win32" (set _vc_arg=x86) else (set _vc_arg=amd64)
call "%VS100COMNTOOLS%..\..\VC\vcvarsall.bat" %_vc_arg%
msbuild /t:build /p:Configuration="%_conf%" /p:Platform=%_arch% %_proj% || set "_code=1"
endlocal & exit /b %_code%
Related
I have the below machine
OS: Windows server 2016
SharePoint: 2016
Visual Studio: 2015 Professional
When we publish any sharepoint project using Visual studio, it produces .wsp file but when we try to build the same using msbuild only .dll is generated but not .wsp file
tried to refer msbuild.exe from framework (msbuild_1 in below code) and programfiles (msbuild_2 in below code)
set msbuild_1 ="C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe"
set msbuild_2 ="C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe"
set config=Release
set outdir2=C:\out\
rd /S /Q "%outdir2%"
%msbuild_1% /p:Configuration=%config% /m "C:\Test\test.csproj" /t:Package /p:BasePackagePath=%outdir2%
%msbuild_2% /p:Configuration=%config% /m "C:\Test\test.csproj" /t:Package /p:BasePackagePath=%outdir2%
both version of msbuild.exe generates only .dll but not .wsp
Is there anyway we can generate .wsp file from msbuild.exe or powershell?
If you want to create a share point package with Msbuild you can refer to the following steps:
Run Command Prompt in the Windows Start menu.
Change to the SharePoint project folder.
Run this command: msbuild /t:Package ProjectFileName change the ProjectFileName to your project name.
You can also refer to this page about how to build, clean, and validate a sharepoint package using command-line MSBuild tasks.
Run the following command in PowerShell after changing the paths
$msbuildpath = ""
$csprojpath = ""
$OutputPath = ""
$vsversion = "14.0"
cd $msbuildpath
.\msbuild.exe $csprojpath /p:IsPackaging=true /p:OutputPath="$OutputPath" /p:Configuration=Release /p:VisualStudioVersion=$vsversion /t:Package
the output will include the WSP files
I'd like to use a script to build translations (convert from .ts to .qm, using Qt's lrelease.exe) before compiling the resource file (QRC) where they are included. In this way I know they are always updated, not to mention to avoid including binary files in the repository.
I use Visual Studio and have installed the Qt Visual Studio Tools. Normally, I'd do this through a pre-build step in the project, but it is not being executed and the compilation of the QRC file always fails.
1>------ Build started: Project: MyApp, Configuration: Release Win32 ------
1>Rcc'ing MyApp.qrc...
1> RCC: Error in 'C:\src\MyApp\MyApp\MyApp.qrc': Cannot find file 'translations/myapp_en.qm'
1>MyApp.qrc : error 1: rcc (c:\Qt\qt_5_12_3\v141\Win32\bin\rcc.exe)
1>Done building project "MyApp.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 12 up-to-date, 1 skipped ==========
The script works correctly and it is called successfully either if placed as a post-build event or from command line.
#echo off
pushd "%1"
for %%F in (*.ts) do (
c:\Qt\qt_5_12_3\v141\Win32\bin\lrelease -compress %%F -qm %%~nF.qm
)
popd
exit /b 0
What I'm I doing wrong?
It happened that I was using the new Qt/MSBuild mode of Qt VS Tools. Internally it generates several hidden targets in the MSBuild workflow, which are executed before the pre-build events.
The solution was to use a custom build step instead, with some specific settings:
Execute before the QtRcc target (the one that actually compiles the resource file)
The Qt VS Tools parses QRC files to check if the resources have been modified, so it can skip compiling them. It is necessary to add the .qm translation files as output of the custom build step.
Similarly, to guarantee translations are always compiled, set dependencies of the custom build step to the .ts source files.
How do I build a solution in MSBuild (command line only) with PGI/PGO without adding new build configuration to projects?
I've tried to add command line parameter /property:WholeProgramOptimization=PGInstrument which looks OK, it creates PGD files but does not create PGC after I ran the application. Obviously I'm missing something in MSBuild command line.
I spent two days scratching my head on this problem and I finally found how to do it:
First you need to build the instrumented version of your program:
msbuild.exe
/t:Rebuild "Letter:\path\YourProject.vcxproj"
/p:Configuration=Release
/p:Platform=x64
/p:WholeProgramOptimization=PGInstrument
Note that On my machine, MSBuild can be found here:
C:\Program Files (x86)\MSBuild\12.0\Bin\msbuild.exe. The order of the parameters are really important. If your project were placed after the /p options, it could overwrite them.
A pgd file should have been created in your output directory. You will need its path later.
Then you need to instrument the program:
Letter:\path\OutPutDir\YourProject.exe
In this step obviously you need to add parameters to feed your program with the data it needs. If your program complains about not having access to pgort120.dll you can add a line like this one to your script: set PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64
Finally you can build the optimized version of your program:
msbuild.exe
/t:LibLinkOnly "Letter:\path\YourProject.vcxproj"
/p:Configuration=Release
/p:Platform=x64
/p:WholeProgramOptimization=PGOptimize
/p:LinkTimeCodeGeneration=PGOptimization
/p:ProfileGuidedDatabase="Letter:\path\OutPutDir\YourProject.pgd"
Here you need to use the address of the pgd file of the first step. Note that the target is LibLinkOnly because there is no need to recompile everything.
Hope this helps others.
Building on the Answer from Arnaud, without which I would never have figured this out, there are additional settings that can be useful. In my solution, I only wanted to build one project out of 20+ with PGO, which required additional flags to prevent all the referenced projects being built:
/p:BuildProjectReferences=false
Use this to stop the projects referenced by the target project being built by the Rebuild target. You need to add this to both the /t:Rebuild command and from VS 16.8.0 onwards to the /t:LibLinkOnly command.
In VS2019, you will find the pgort140.dll buried in the:
Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.21.27702\bin\HostxNN\xNN
folder, where xNN is x86 or x64 as appropriate.
In the case of a solution, you are likely to have a $(OutDir) output location that depends on solution settings, but that when you build a separate project ends up in the wrong place, so you will all likely need to tell the Project file where the output is with:
/p:OutDir="path to output"
In my case, with a solution file holding lots of projects and one that I need to run with PGO I ended up with a batch file (see below). In this case, at the top level I
have a solution file MyApp.sln that contains many sub-projects in sub-folders. The
one I want is called subproj and lives in the subprob folder with a project file
called subproj.vcxproj in that folder. Each sub-project generates a DLL and there
are dependencies from subproj on other sub-projects. The gist of the batch file is
as follows:
REM Get the folder we are running out of, assumed to hold the solution file
SET parent=%~dp0
REM Set PLATFORM=x64, TOOLS=HOSTx64\x64 for 64-bits
SET PLATFORM=Win32
SET TOOLS=Hostx86\x86
ECHO Build %PLATFORM% Release of MyApp with PGO of the subprog project
REM Expanding Program Files (x86) causes problems so use PROGRA~2
SET VSPATH=C:\PROGRA~2\Microsoft Visual Studio\2019\Professional
REM Value for VS 16.?.? = \14.21.27702
REM Value for VS 16.3.2 = \14.22.27905\bin
REM Value for VS 16.3.3 = \14.23.28105\bin
REM Value for VS 16.4.0 = \14.24.28314\bin
REM Value for VS 16.5.0 = \14.25.28610
REM Value for VS 16.6.0 = \14.26.28801
REM Value for VS 16.7.0 = \14.27.29110
REM Value for VS 16.8.0 = \14.28.29333
SET VSTOOLS=%VSPATH%\VC\Tools\MSVC\14.21.278.29333\bin
if not exist "%VSTOOLS%" (
ECHO %VSTOOLS% Was not found. This is probably due to a new release. Please
ECHO find the new location and correct this batch file:
ECHO %parent%%me%.bat
exit /b 1
)
REM Set tools path (needed to locate the pgoNnn.dll used for PGO)
set PATH=%PATH%;%VSTOOLS%\%TOOLS%
REM MSB is the path to the MSBuild.exe command
SET MSB="%VSPATH%\MSBuild\Current\Bin\MSBuild.exe"
REM OPT is the common options shared by everything
REM /v: n=normal, m=minimal, q=quiet
SET OPT=/v:m /p:Configuration=Release /p:Platform=%PLATFORM%
REM Set where our output must go. VS likes it to end with \ for $(OutDir)
SET OUTDIR=%parent%%PLATFORM%\Release\
REM It is easier to build everything and rebuild subproj that build all the
REM sub-projects separately.
echo Build the entire solution in the Release build for the desired platform.
%MSB% MyApp.sln %OPT%
echo Now instrument the subproj
%MSB% /t:Rebuild "subproj\subproj.vcxproj" %OPT% /p:OutDir=%OUTDIR% /p:WholeProgramOptimization=PGInstrument /p:BuildProjectReferences=false
echo Run MyApp to exercise the subproj DLL as needed to generate the PGO database
%parent%%PLATFORM%\Release\MyApp.exe arguments as required...
echo Now build PGO optimized version of subproj
%MSB% /t:LibLinkOnly "subproj\subproj.vcxproj" %OPT% /p:WholeProgramOptimization=PGOptimize /p:LinkTimeCodeGeneration=PGOptimization /p:OutDir=%OUTDIR% /p:ProfileGuidedDatabase="%OUTDIR%compiler.pgd" /p:BuildProjectReferences=false
set Unified=C:\Workspaces\Main\Unified\UnifiedFX.sln
set Fullserver=C:\Workspaces\Main\Unified\FullServer\Tests\FullServer.Automation\FullServer.Automation.csproj
set Management=C:\Workspaces\Main\Unified\Management\Tests\Management.Automation\Management.Automation.csproj
set Move=C:\Workspaces\Main\Unified\Move\Tests\Move.Automation\Move.Automation.csproj
set d64="Debug|x64"
set d86="Debug|x86"
for %%a in (%d64%, %d86%) do (
for %%b in (%Fullserver%, %Move%, %Management%) do (
devenv %Unified% /build %%a /project %%b))
That's my .bat file. When I run it it takes near-ish 90 seconds to complete. Yet I can build each individual project from within Visual Studios 2010 in just a couple seconds, plus the time it takes to switch between x64 and x86. Why is the bat file so slow?
You are loading visual studio for each project, I will bet that it's this that is the most time consuming.
Instead of running devenv.exe to run the build, just use MSBUILD.EXE on the csproj or sln files.
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 various things so far, MSBuild, aspnet_compiler, but nothing, to date has worked.
I need to be able to specify the Project, not the solution, have any transforms run and have the output redirected to a folder...basically mimick the right mouse click 'Publish' option, using the File System.
In addition to all of this, I'd like to leave the projects alone - not adding msbuild files all over the place, as this is a specific build, and not necessarily related to the project.
Stuff I've tried:
Publish ASP.NET MVC 2 application from command line and Web.config transformations
Equivalent msbuild command for Publish from VS2008
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)
<Target Name="PublishToFileSystem" DependsOnTargets="PipelinePreDeployCopyAllFilesToOneFolder">
<Error Condition="'$(PublishDestination)'==''" Text="The PublishDestination property must be set to the intended publishing destination." />
<MakeDir Condition="!Exists($(PublishDestination))" Directories="$(PublishDestination)" />
<ItemGroup>
<PublishFiles Include="$(_PackageTempDir)\**\*.*" />
</ItemGroup>
<Copy SourceFiles="#(PublishFiles)" DestinationFiles="#(PublishFiles->'$(PublishDestination)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="True" />
</Target>
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
I know this is an old question, but I just learned something, so I decided I'd share: While it is 100% true that the "_CopyWebApplication" target exists and works, as of .NET 4.0 it has been superseded by the "_WPPCopyWebApplication" target in Microsoft.Web.Publishing.targets, which supports new features like web.config transformation syntax, etc.
Have you checked out WebDeploy?
This should do all the steps you need to have - it can bundle up a web app into a deployable file (a ZIP, basically), and there's an "engine" on the server that can interpret that deployable package and do all the heavy lifting for you.
Also see Scott Hanselman's Web Deployment Made Awesome: If You're Using XCopy, You're Doing It Wrong blog post - very enlightening!
My solution for CCNET with the Web.config transformation:
<tasks>
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>
<workingDirectory>E:\VersionesCC\Trunk_4\SBatz\Gertakariak_Orokorrak\GertakariakMS\Web</workingDirectory>
<projectFile>GertakariakMSWeb2.vbproj</projectFile>
<targets>Build</targets>
<timeout>600</timeout>
<logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
<buildArgs>
/noconsolelogger /p:Configuration=Release /v:diag
/p:DeployOnBuild=true
/p:AutoParameterizationWebConfigConnectionStrings=false
/p:DeployTarget=Package
/p:_PackageTempDir=E:\Aplicaciones\GertakariakMS2\Web
</buildArgs>
</msbuild>
</tasks>