Using PublishProfile in MSBuild for Database Project - msbuild

I have a database project in Visual Studio 2012. I am trying to create an MSBuild project to publish the database on the build server. In my solution, I have a Publish Profile that I would like to use on the build server.
I have the following target setup:
<Target Name="BuildDatabases">
<MSBuild Projects="$(DBProjectPath)" Targets="Build;Deploy" Properties="DeployOnBuild=true;SqlPublishProfilePath=BuildServer.publish">
</MSBuild>
</Target>
I've tried a combination of PublishProfile and SqlPublishProfilePath to no avail. I always receive:
Deploy Error: The connection string is not valid
I can use the Publish Profile inside VS with no connection issues.

Figured it out:
<Target Name="BuildDatabases">
<MSBuild Projects="$(DBProjectPath)" Targets="Build;Publish" Properties="DeployOnBuild=true;SqlPublishProfilePath=BuildServer.publish.xml">
</MSBuild>
</Target>
I had to use "Build;Publish" for target, I was using "Build;Deploy"

Related

Config Transform in Azure DevOps

I would like to use a visual studio proj file to transform xml files. I am following this article. http://sedodream.com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx . This works for me locally, however when deploying the application on Azure DevOps it fails. It cannot find Microsoft.Web.Publishing.Tasks.dll. How do I set up a build task that will only transform the config files.
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TransformXml"
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>
<Target Name="Build">
<TransformXml Source="Web.config"
Transform="Web.Release.config"
Destination="Web.Production.config" />
</Target>
</Project>
Turned out to be an easy fix. It was an old build so that the hosted agent. Just had to change it to the Hosted VS2017 agent.
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>
I think that's why the issue happens. For a vs2017 agent, you need to change the v10.0 to v15.0, so that the msbuild tool can find the assembly.
Also, as for vs2017, make sure you set the correct msbuild tool path in VSTS like this issue.

MSBuild ClickOnce app: FTP Upload files after build

I am using MS build to publish my ClickOnce app, in Visual Studio 2017 developer command line to a remote ftp site.
How do I initiate the FTP file upload that starts in Visual Studio after build? This is my command line, which builds the project:
msbuild /target:publish -property:Configuration=Release /p:PlatformTarget=x86 "%USERPROFILE%\VSProjects\IIC\IIC.UI.vbproj"
There are 2 problems with command line Click Once deployment: (1) Auto Incrementing option from the publish property page of a project is not honored from the command line, and (2) the subject of the question, starting the FTP upload to the remote site.
Solution (with Visual Studio 2017 Developer Command Prompt v15.7.3)
Download community ms build tasks from here: https://github.com/loresoft/msbuildtasks
Unload the project and open with notepad++ or your editor of choice and import the community ms build tasks. Follow the instructions on their github page.
Add file ProjectName.version.txt with just one line with the version information of your project. For example:
1.2.78.1341
The numbers correspond to {Major}.{Minor}.{Build}.{ApplicationRevision}
Add the following target to the bottom of the project, which uses the Version and FileUpdate community tasks:
<Target Name="beforePublishCmd">
<Message Text="revision before: 3.0.0.$(ApplicationRevision)"/>
<Version VersionFile="ProjectName.version.txt" BuildType="Automatic" Major="3" Minor="0" Build="0" RevisionType="Increment">
<Output TaskParameter="Major" PropertyName="Major" />
<Output TaskParameter="Minor" PropertyName="Minor" />
<Output TaskParameter="Build" PropertyName="Build" />
<Output TaskParameter="Revision" PropertyName="ApplicationRevision" />
</Version>
<Message Text="revision after: 3.0.0.$(ApplicationRevision)"/>
<FileUpdate Files="ProjectName.vbproj"
Regex="<ApplicationRevision>(\d+)"
ReplacementText="<ApplicationRevision>$(ApplicationRevision)" />
</Target>
Call the above target from the command line BEFORE calling the publish target, like so:
msbuild /target:beforePublishCmd -property:Configuration=Release /p:PlatformTarget=x86 "%USERPROFILE%\VSProjects\ProjectName.vbproj"
Add an "afterPublish" target, which uses the FtpUploadDirectoryContent community task. This target is automatically called after the publish target finishes.
<Target Name="afterPublish">
<PropertyGroup>
<CurrentDate>$([System.DateTime]::Now.ToString(yyyy MMM dd HH:mm:ss))</CurrentDate>
</PropertyGroup>
<FtpUploadDirectoryContent
ServerHost="projectname.org"
Username="*****"
Password="*****"
LocalDirectory=".\bin\Release\app.publish"
RemoteDirectory="/"
Recursive="true"
/>
<Exec Command="C:\Progra~1\TortoiseSVN\bin\svn commit ..\ --non-interactive --message "Release 3.0.0.$(Revision) on $(CurrentDate): $(commitMessage)""/>
</Target>
Finally, call the publish target from the command line:
msbuild /target:publish -property:Configuration=Release /p:PlatformTarget=x86 "%USERPROFILE%\VSProjects\ProjectName.vbproj"
MSBuild ClickOnce app: Upload files after build
You can add a copy task into your project file to upload files after build:
To accomplish this, unload your project. Then at the very end of the </project>, just before the end-tag, place below scripts:
<ItemGroup>
<UploadFiles Include="ThePathOfYourUploadFiles\*.*"/>
</ItemGroup>
<Target Name="AfterBuild">
<Copy
SourceFiles="#(UploadFiles)"
DestinationFolder="PathWhereYouWantTouploadYourUploadFiles"
/>
</Target>
With this target, Visual Studio/MSBuild will upload the files after build.
Hope this helps.

MSbuild run specific targets for specific projects

I am using following code in 2 our of 3 projects from the solution default target is set to PublishMe
<Target Name="PublishMe" 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>
If I run msbuild it builds and publishes just as expected, the problem is that I can't build it from VS anymore, I am having error of missing projectname.dll
Is there way I can change default build target if it is msbuild doing build?
I tried to /t:ProjectName:target;ProjectName2:target, but it isn't working with custom targets for some reason.
Is there way I can specify param from msbuild console to run PublishMe target and if not present run simple build?
You can usefollowing command
msbuild projectname /t:targetname.
Also please check the below link for more info
Building a solution file using msbuild

TFS 2010 build Server Wix. Output only MSI

I've managed to get builds working on my build server, but now the issue I have is that the output in the output folder contains all output from all projects, rather than just the output from the wix project(s).
Any idea how to change this?
TIA
If you are only interested in the msi as a build output then you could create a step in your team build to copy your installer files to another location, the following build target, added to your build project should help.
This overrides the target AfterDropBuild
<Target Name="AfterDropBuild">
<PropertyGroup>
<InstallerDir>$(DropLocation)\$(BuildNumber)\Installers</InstallerDir>
</PropertyGroup>
<Message Importance="low" Text="InstallerDir=$(InstallerDir)" />
<MakeDir Directories="$(InstallerDir)" Condition="!Exists('$(InstallerDir)')" />
<CreateItem Include="$(BinariesRoot)\**\*.msi">
<Output TaskParameter="Include" ItemName="InstallationFiles"/>
</CreateItem>
<Copy SourceFiles="#(InstallationFiles)"
DestinationFolder="$(InstallerDir)"/>
</Target>
I create different solution platforms { Application, Setup } and set my .NET projects to build with application and my wix to build with setup. Then I tell the build definition to build those two platforms in that order. The result is that TFS archives the .NET code in an application folder that looks like the deployed machine and the MSI in the setup folder.
Only downside is when you add new projects you have to select the platform to build in configuration manager. My developers don't seem annoyed by it though.

TFS build server

We are just getting started with TFS 2010 and migration from SVN and CruiseControl.NET to TFS.
With cruisecontrol.NET we have a powershell script that does everything: copying, modifying, compressing files.
Now my question is how we can integrate that script into the TFS build server? Modifying the solution or creating a custom msbuild file?
Also I would like to combine this with Web Packaging. Any idea how this can be accomplished?
My recommendation is to create a custom msbuild file. In this file call build of your solution and then call your powershell script. Like:
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<!-- Compile whole solution in release mode -->
<MSBuild
Projects="MySolutionFile.sln"
Targets="ReBuild"
Properties="Configuration=Release" />
<Exec
Command=“command_for_run_cutom_script“
ContinueOnError="false"
WorkingDirectory="." />
</Target>
</Project>
However consider rewriting your powershell script fully to msbuild script. You will get better maintenance. Copying, modifying, compressing files… are no problem for msbuild.
http://tfsccnetplugin.codeplex.com/ has all the documentation you need in terms of Configuring CCNet with TFS, as for the web packaging...unfortunately someone else will have to help with that.