I have a standard sql server 2008 project which has been created using vs2010. I have been trying to modify the build process so that at the end a custom task should fire which would call VSDBCMD to generate a deploy script by comparing the output of the build (the dbschema file) against a static DBschema file. When I run this command from a VS2010 command prompt
vsdbcmd.exe /a:deploy /dd:- /dsp:sql /model:obj\Release\EnterpriseBuild.Services.Database.dbschema /targetmodelfile:VersionedSchemas\v1.0.dbschema /DeploymentScriptFile:NewDeploymentScript.sql /p:TargetDatabase="EnterpriseBuild.Database"
Everything works great and the newdeployment.sql file is generated. However when I modify my .dbproj file and include this as a AfterBuilds Target
<Target Name="AfterBuild">
<!--<Message Text="sample text" Importance="high"></Message>-->
<Exec IgnoreExitCode="false"
WorkingDirectory="C:\Program Files (x86)\Microsoft Visual Studio 10.0\VSTSDB\Deploy\"
Command="vsdbcmd.exe /a:deploy /dd:- /model:obj\Release\EnterpriseBuild.Services.Database.dbschema /targetmodelfile:VersionedSchemas\v1.0.dbschema /DeploymentScriptFile:NewDeploymentScript.sql /p:TargetDatabase="EnterpriseBuild.Database"" />
</Target>
the build fails with a
EnterpriseBuild.Services.Database.dbproj(211,5): error MSB3073: The command "vsdbcmd.exe /a:deploy /dd:- /model:obj\Release\EnterpriseBuild.Services.Database.dbschema /targetmodelfile:VersionedSchemas\v1.0.dbschema /DeploymentScriptFile:NewDeploymentScript.sql /p:TargetDatabase="EnterpriseBuild.Database"" exited with code 1.
message.
Can anyone suggest what I am doing wrong?
Visual Studio also exposes $(VSTSDBDirectory) - location of VSDBCMD
MSBuild task could look as follows:
<Exec Command=""$(VSTSDBDirectory)\Deploy\VSDBCMD" /a:Deploy /q+ /dd:+ /dsp:sql /manifest:"$(OutDir)Database.deploymanifest" /cs:"Integrated Security=SSPI;Persist Security Info=False;Data Source=(local)" /p:AlwaysCreateNewDatabase=true /p:CommentOutSetVarDeclarations=false /p:TargetDatabase="MyDatabase" /Script:"$(OutDir)MyDatabase.sql"" ContinueOnError="false" />
I managed to solve it. Basically doing this
<Target Name="AfterBuild">
<!--<Message Text="sample text" Importance="high"></Message>-->
<Exec IgnoreExitCode="false"
WorkingDirectory="C:\Program Files (x86)\Microsoft Visual Studio 10.0\VSTSDB\Deploy\"
Command="vsdbcmd.exe /a:deploy /dd:- /model:obj\Release\EnterpriseBuild.Services.Database.dbschema /targetmodelfile:VersionedSchemas\v1.0.dbschema /DeploymentScriptFile:NewDeploymentScript.sql /p:TargetDatabase="EnterpriseBuild.Database"" />
</Target>
rightly sets the working directory to C:\Program Files(x86)....where my VersionedSchemas\v1.0.dbschema etc. don't exist. The trick was to keep the working directory same as the ProjectDirectory and still call VSDBCMD. I managed this by doing
<Exec IgnoreExitCode="false" Command=""C:\Program Files (x86)\Microsoft Visual Studio 10.0\VSTSDB\Deploy\vsdbcmd" /a:deploy /dd:- /model:obj\Release\EnterpriseBuild.Database.dbschema /targetmodelfile:VersionedSchemas\v1.0.dbschema /DeploymentScriptFile:NewDeploymentScript.sql /p:TargetDatabase="EnterpriseBuild.Database"" />
The trick was to use & quot; around C:\Pro...
Related
I am trying to publish a Visual stuido Project from another Project, to do this I have created a bat file which runs my MSBuild file. If you run this outside of Visual Studio it works correctly but when i tried to add it to Visual Studio's prebuild scripts it does not publish. I am getting this warning -
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3247: Found confl
icts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select
it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the a
pplication configuration file
My MSBuild file:
<Target Name="BeforeBuild">
<MSBuild
Projects="E:\Development\alyz\myAPI\View.API.sln"
Targets="View_API_Search"
Properties="DeployOnBuild=true;Configuration=Release;PublishProfile=InstallerPublish;WebPublishMethod=FileSystem;PublishURL=E:\Temp\installertemp\SearchAPI" />
</Target>
Visual Studio is saying that my project has built correctly but i can't work out why it's not publishing, any ideas?
Visual Studio is saying that my project has built correctly but i can't work out why it's not publishing, any ideas?
You can use another solution for this issue. Following is my publish target, you can check it:
<Target Name="BeforeBuild">
<Exec Command=""<YourMSBuild.exePath>\msbuild.exe" "<YourSolutionPath>\View.API.sln" /p:DeployOnBuild=true /p:PublishProfile=InstallerPublish.pubxml /p:Configuration=Release /p:PublishURL=E:\Temp\installertemp\SearchAPI"></Exec>
</Target>
With this target, the project/solution will be build and published when you build the project.
Hope this helps.
ClickOnce publish with IDE works normal.
When trying to publish via MSBuild command line
%MSBUILD% /target:publish /p:Configuration=Release;PublishDir="REMOTE_FOLDER"
only Project.exe and Setup.exe copies.
When try to %MSBUILD% /target:publish command then all necessary files copies to the build\app.publish folder
How do I publish via command line same ClickOnce settings which IDE uses
PS this question similar but not the same
How do I publish via command line same ClickOnce settings which IDE uses
Some features are done by Visual-Studio and not by the MSBuild command line. So the click-once-deployment behaves differently when it's executed from the command-line.
If you want to publish via command line same ClickOnce settings which IDE uses, you can use a custom target to achieve it. Edit your project(csproj) file (right click project node -> unload project -> edit xxx.csproj) and add the following code in it:
<PropertyGroup>
<ProjLocation>D:\Test\Projects\ClickOncePublish\ClickOncePublish</ProjLocation>
<ProjLocationReleaseDir>$(ProjLocation)\bin\Debug</ProjLocationReleaseDir>
<ProjPublishLocation>$(ProjLocationReleaseDir)\app.publish</ProjPublishLocation>
<DeploymentFolder>D:\Test\Publish\</DeploymentFolder>
</PropertyGroup>
<Target Name="Test" DependsOnTargets="Clean">
<MSBuild Projects="$(ProjLocation)\$(ProjectName).csproj"
Properties="$(DefaultBuildProperties)"
Targets="Publish"/>
<ItemGroup>
<SetupFiles Include="$(ProjPublishLocation)\*.*"/>
<UpdateFiles Include="$(ProjPublishLocation)\Application Files\**\*.*"/>
</ItemGroup>
<Copy SourceFiles="#(SetupFiles)" DestinationFolder="$(DeploymentFolder)\" />
<Copy SourceFiles="#(UpdateFiles)" DestinationFolder="$(DeploymentFolder)\Application Files\%(RecursiveDir)"/>
</Target>
<Target Name="Clean">
<Message Text="Clean project" />
<MSBuild Projects="$(ProjLocation)\$(ProjectName).csproj"
Properties="$(DefaultBuildProperties)"
Targets="Clean"/>
</Target>
Then you can build the project with the MSBuild command line:
msbuild /target:test
After execute the build command, all the expected files are publish via command line same ClickOnce settings which IDE uses.
Note: You should change the value of ProjLocation to the path of your project.
I want to run tools that belong to the VS installation folder from within a .csproj file.
If I run the supplied script:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvars32.bat
then %VSINSTALLDIR% is defined
But inside the .csproj file, it is not defined.
<Target Name="RunNpmGulpBower" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="Call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvars32.bat" && npm.cmd install" />
This will not work and bower.cmd will not be found.
Is there any workaround for this?
I have .sln file which has around 352 projects.
I have created batch file below
"C:/Windows/Microsoft.NET/Framework/v4.0.30319/msbuild.exe myproj.sln /nologo /t:Build /p:Configuration="Debug" /property:Platform="Win32"
pause"
But this builds all the projects from solution. I have configured "Configuration Manager" to unselect unwanted projects or unload project and used above batch file to build but that did not serve the purpose.
I have searched MSBuild options but could not find exact answer.
Can anyone help me in this ?
MSbuild accepts project name as part of "target" (/t) specification:
MSBuild /nologo /t:ProjectName:Build SolutionFile.sln
Or, if your project does not depend on other projects in solution, directly use project file with MSBuild:
MSBuild /nologo /t:Build ProjectFile.vcxproj
This trick works with Visual Studio 2010, 2012, 2013, 2015, 2017, 2019 and with the latest MSVS 2022.
You could make a solution containing just the projects you want to build. Alternatively you could make an MSBuild .proj file that collects together the projects you want to build:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ProjectsToBuild Include="X.csproj;Child\Y.csproj" />
</ItemGroup>
<PropertyGroup>
<Configuration>Release</Configuration>
</PropertyGroup>
<Target Name="Build">
<MSBuild Projects ="#(ProjectsToBuild)" ContinueOnError ="false" Properties="Configuration=$(Configuration)">
<Output ItemName="OutputFiles" TaskParameter="TargetOutputs"/>
</MSBuild>
</Target>
</Project>
Derived from http://sedodream.com/PermaLink,guid,ed3a0c98-fdac-4467-9116-5b3bf6755abc.aspx.
We have a WinXP Jenkins build machine that I'm in the process of moving over to a 64bit Win-7 machine. We are utilizing Wix to build the msi's via MSBuild..all these projects sit in TFS. We are getting the TFS changeset number in order set to current build in each project. The line in question in many of our [projectname].wixproj files looks like :
<Target Name="BeforeBuild">
<MSBuild.Community.Tasks.Tfs.TfsClient ToolPath="C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE" Command="history /stopafter:1 /version:T /format:detailed /recursive $(ProjectDir)">
<Output TaskParameter="Changeset" PropertyName="Changeset" />
</MSBuild.Community.Tasks.Tfs.TfsClient>
<Message Text="TFS ChangeSetNumber: $(Changeset)" />
<PropertyGroup>
<DefineConstants>ChangesetNumber=$(Changeset)</DefineConstants>
</PropertyGroup>
</Target>
This works fine on our 32-bit machine but fails on the new 64 bit because the toolpath for TF.EXE is now in c:\Program Files (x86)... instead of C:\program files... I'm trying to figure out a way to make this toolpath variable so we can continue to use both build machines (for now) without dedicating the wix project file to one or the other (without breaking one of the build machines, basically).
This tf.exe toolpath is configured easily in Jenkins on a per-machine basis, but this isn't propagated down into the projects themselves...unless there's a path variables I'm unaware of? Thanks.
You can calculate the root tool path in a msbuild variable.
First set the default value for windows 64 bits subfolder and then depending on an environment variable set the value for 32 bits where that variable is undefined in 32 bits machine.
<PropertyGroup>
<MyProgramFiles>C:\Program Files (x86)\</MyProgramFiles>
<MyProgramFiles Condition=" '$(CommonProgramW6432)' == '' ">C:\Program Files\</MyProgramFiles>
</PropertyGroup>
So passing that variable to your .wixproj will look something like:
<Target Name="BeforeBuild">
<PropertyGroup>
<MyProgramFiles>C:\Program Files (x86)\</MyProgramFiles>
<MyProgramFiles Condition=" '$(CommonProgramW6432)' == '' ">C:\Program Files\</MyProgramFiles>
</PropertyGroup>
<MSBuild.Community.Tasks.Tfs.TfsClient ToolPath="$(MyProgramFiles)\Microsoft Visual Studio 10.0\Common7\IDE" Command="history /stopafter:1 /version:T /format:detailed /recursive $(ProjectDir)">
<Output TaskParameter="Changeset" PropertyName="Changeset" />
</MSBuild.Community.Tasks.Tfs.TfsClient>
<Message Text="TFS ChangeSetNumber: $(Changeset)" />
<PropertyGroup>
<DefineConstants>ChangesetNumber=$(Changeset)</DefineConstants>
</PropertyGroup>
</Target>
I hope this help you.