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
Related
I have created InstallShield Basic MSI project from Visual Studio (IS 2012 Spring, VS 2010). My InstallShield project having 2 product configurations and each configuration having one release.
Product Configuration 1
Release 1
Product Configuration 2
Release 2
For building project in VS IDE, I need to set the corresponding product configuration as 'Default Product Configuration' and build. This is working fine. The Default configuration release is getting build.
But, how can we achieve this in MSBuild command line?
I need to build both configuration separately using MSBuild command line (without changing Default configuration through IDE).
Could anyone please share the proper way to build IS project in MSBuild command line?
Thanks,
Saravanan
how can we achieve this in MSBuild command line?
You can use Properties in the MSBuild command line:
msbuild test.sln /t:project /p:Configuration="Release" /p:Platform="x86" /p:BuildProjectReferences=false
You can also build multiple projects at once:
msbuild test.sln /t:project;project2 /p:Configuration="Release" /p:Platform="x86" /p:BuildProjectReferences=false
Note:
what is assigned to /t is the project name in the solution, it can be different from the project file name.
One important note: if your project has a '.' in the name, you'll need to replace it with a '_' when specifying it with /t
I'm setting up a Jenkins job for a Windows 10 application.
I need to compile one of the four projects inside the solution with devenv.com executable because it is a project with .vdproj extension (setup project).
The other projects are built successfully with MSBuild without any problem.
The Jenkins job ends successfully when I'm logged in as root on a Jenkins target node, but, fails when I run the job from Jenkins and I'm not logged in.
Need your help or workaround to solve the issue.
PS: we are using ant as task runner and we have a specific task that start the build process.
EDIT 26/01/2017
I would like to provide you other informations like the error message and one step that I've skipped before.
The error message provides a link to a Microsoft Page and reports a configuration problem.
As solved by this StackOverflow post, I've added a new DWORD registry key under
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\14.0_Config\MSBuild\EnableOutOfProcBuild
Can the problem be that this value can't be readed when the User is'nt logged in ?
EDIT 27/01/2017
I'm going crazy with this issue.
The command devenv /? work fine when i run it locally but wont work when i run it from Jenkins with the same error as before: Microsoft Visual Studio found a configuration problem. To fix it restart as administrator or visit http://go.microsoft.com/fwlink/?LinkId=659046 for further information.
So the devenv.com cannot be executed when i'm not logged in ??
UPDATED 31/01/2017#
Here's my .bat file called from a target by ant build.xml
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat"
#set MSBUILD="C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe"
%MSBUILD% "%cd%\src\AutomatedSetupBuild.proj"
pause
Where the AutomatedSetupBuild.proj is an MSBuild script
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Target Name="Build">
<PropertyGroup>
<DevEnv>C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.com</DevEnv>
<SolutionFile>$(MSBuildProjectDirectory)\MySolution.sln</SolutionFile>
<ProjectFile>MySetupProject\MySetupProject.vdproj</ProjectFile>
<Configuration>Release</Configuration>
</PropertyGroup>
<Exec
Command=""$(DevEnv)" "$(SolutionFile)" /Rebuild "$(Configuration)" /Project "$(ProjectFile)" /ProjectConfig "$(Configuration)" /Log vs.log /useenv"
ContinueOnError="false"
IgnoreExitCode="false"
WorkingDirectory="$(MSBuildProjectDirectory)" />
</Target>
</Project>
As you can see, I'm loading the environment variable before run devenv.com but i receive the same error.
Do you use a free style job or do you use a Jenkinsfile for a pipeline project? In any case, for devenv.com to work, environment variables have to be set up.
Please go to the Windows start menu and look for something like Visual Studio XX -> Visual Studio Tools -> Developer Command Prompt for VS20XX. Press right mouse bottom and select properties. There look for target. In my case this field contains the following string:
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat""
If you use e.g. a Jenkinsfile, change the call to devnenv.com, which probably looks like
bat "devenv.com my_solution_file.sln /project my_project /build \"Release|x64\""
to
bat "call \"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat\"; devenv.com my_solution_file.sln /project my_project /build \"Release|x64\""
It is important, that the call to the VsDevCmd.bat is within the same bat command. Otherwise the environment variable settings get lost and are not seen by a second call to bat.
Open the dev command prompt type "where devenv" then call the full path with the .com version... e.g.
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.com" /Rebuild "RELEASE|Win32" "F:\project.sln"
For my part, I had to convert the Visual Studio 2015 SSRS project to SSRS Visual Studio 2017. Then I installed the 2017 SSDT for VS 2017, and use MSBUILD. Everything works well without open remote session.
I have a Visual Studio 2013 project. I need to deploy it to remote Windows Server via command line, is this possible?
I tried the following command:
MSBuild.exe C:\BuildAgent\work\e1434fd989e26b76\WebService.csproj /T:Package /P:Configuration=Release
This packages the project for me. Now what should I do to deploy it to the server via command line?
Create a new custom publish profile from visual studio. After creating it validate the connection from visual studio.Save this profile.Now in Properties/PublishProfiles there will be the new publish profile.pubxml.
After that try this.
msbuild "PATH_TO_SOLUTION_FILE" /p:DeployOnBuild=true /p:PublishProfile="PATH_TO_PUBLISH_PROFILE" /p:AllowUntrustedCertificate=true /p:UserName=USER_NAME /p:Password=PASSWORD
If you are executing the above from solution file path then just mention the solution name and publishing profile name. There is no need to give the entire path.
You can define a publishing profile and deploy by calling an msbuild.exe with:
/p:DeployOnBuild=true /p:PublishProfile=Foo
This is described here:
http://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/command-line-deployment
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
I am copying .exe file form a separate to my main project's folder on prebuild event but I need to build that project before build my main project so i want to build that project on prebuild event of my main project.
Not that this is the best solution, but it will definitely work for what you want to do: Put the below into your pre-build event
"$(VS100COMNTOOLS)..\IDE\devenv" "csproj location OR sln location" /Rebuild "configuration required if you have more than configuration ex: Debug|x64"
This is what worked for me:
"$(DevEnvDir)devenv" "$(SolutionDir)MySolution.sln" /Build $(configuration) /project "$(SolutionDir)MyProjectFolder\MyProject.csproj"
Here $(DevEnvDir), $(SolutionDir), and $(configuration) are Visual Studio Macros, so this command will be translated into:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv" "D:\Learning\MySolutionFolder\MySolutionName.sln" /Build Debug /project "D:\Learning\MySolutionFolder\MyProjectFolder\MyProject.csproj"
"$(DevEnvDir)devenv" "$(SolutionPath)" /Rebuild $(configuration) /project "$(SolutionDir)MyProjectFolder\MyProject.csproj"
Tested now on Visual Studio Community 16.11.1
Using the below command in visual studio 2019, build is faster with msbuild as compared to "$(DevEnvDir)devenv".
msbuild "$(SolutionDir)Sample.sln" /p:configuration=$(configuration)