Thursday, 29 June 2017

Using IIS Publishing Packages With Visual Studio Online Builds

When you create a publishing profile for a web service in Visual Studio it generates an XML file while looks like this:-

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>Package</WebPublishMethod>
    <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <PrecompileBeforePublish>True</PrecompileBeforePublish>
    <EnableUpdateable>True</EnableUpdateable>
    <DebugSymbols>False</DebugSymbols>
    <WDPMergeOption>DonotMerge</WDPMergeOption>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <DesktopBuildPackageLocation>bin\MyWebService.zip</DesktopBuildPackageLocation>
    <PackageAsSingleFile>true</PackageAsSingleFile>
    <DeployIisAppPath>Default Web Site/MyWebService</DeployIisAppPath>
    <PublishDatabaseSettings>
      <Objects xmlns="">
        <ObjectGroup Name="MyDatabase" Order="1" Enabled="False">
          <Destination Path="" />
          <Object Type="DbDacFx">
            <PreSource Path="Trusted_Connection=True;Persist Security Info=False;Initial Catalog=MyDatabase;Data Source=.;" includeData="False" />
            <Source Path="$(IntermediateOutputPath)AutoScripts\MyDatabase_IncrementalSchemaOnly.dacpac" dacpacAction="Deploy" />
          </Object>
          <UpdateFrom Type="Web.Config">
            <Source MatchValue="Trusted_Connection=True;Persist Security Info=False;Initial Catalog=MyDatabase;Data Source=.;" MatchAttributes="$(UpdateFromConnectionStringAttributes)" />
          </UpdateFrom>
        </ObjectGroup>
      </Objects>
    </PublishDatabaseSettings>
  </PropertyGroup>
  <ItemGroup>
    <MSDeployParameterValue Include="$(DeployParameterPrefix)MyDatabase-Web.config Connection String" />
  </ItemGroup>
</Project>

This works well if you are deploying from within Visual Studio or importing an application in IIS.

However if you are setting up a Visual Studio Online (VSO) build and release you will need to make some extra modifications to ensure that the correct connections are used for your different environments.

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>Package</WebPublishMethod>
    <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <PrecompileBeforePublish>True</PrecompileBeforePublish>
    <EnableUpdateable>True</EnableUpdateable>
    <DebugSymbols>False</DebugSymbols>
    <WDPMergeOption>DonotMerge</WDPMergeOption>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <DesktopBuildPackageLocation>bin\MyWebService.zip</DesktopBuildPackageLocation>
    <PackageAsSingleFile>true</PackageAsSingleFile>
    <DeployIisAppPath>Default Web Site/MyWebService</DeployIisAppPath>
    <PublishDatabaseSettings>
      <Objects xmlns="">
        <ObjectGroup Name="MyDatabase" Order="1" Enabled="False">
          <Destination Path="" />
          <Object Type="DbDacFx">
            <PreSource Path="Trusted_Connection=True;Persist Security Info=False;Initial Catalog=MyDatabase;Data Source=.;" includeData="False" />
            <Source Path="$(IntermediateOutputPath)AutoScripts\MyDatabase_IncrementalSchemaOnly.dacpac" dacpacAction="Deploy" />
          </Object>
          <UpdateFrom Type="Web.Config">
            <Source MatchValue="Trusted_Connection=True;Persist Security Info=False;Initial Catalog=MyDatabase;Data Source=.;" MatchAttributes="$(UpdateFromConnectionStringAttributes)" />
          </UpdateFrom>
        </ObjectGroup>
      </Objects>
    </PublishDatabaseSettings>
  </PropertyGroup>
  <ItemGroup>
    <MSDeployParameterValue Include="$(DeployParameterPrefix)MyDatabase-Web.config Connection String">
      <ParameterValue>Data Source=.;Initial Catalog=MyDatabase;Integrated Security=True</ParameterValue>
    </MSDeployParameterValue>
  </ItemGroup>
</Project>

In this version of the file we have explicitly set the MSDeployParameterValue for our connection which, as the name suggests, is going to be used by the MSDeploy utility to configure the web service when we release.

Friday, 23 June 2017

Visual Studio Fun With Shift, Ctrl and Alt

Friday afternoon so here's a few cool tips for Visual Studio (especially Visual Studio 2017) in the code window.


  • Left Mouse Click - position cursor (obviously)
  • Alt Left Mouse Click - position cursor (no excitement yet)
  • Shift Left Mouse Click - highlight text between the original cursor position and the new one
  • Ctrl Left Mouse Click - open an embedded window with the code definition of the thing you clicked on! And you can edit this while also editing the main code window!!
  • Left Mouse Drag - Highlights between the starting drag position and the finishing one, wrapping the highlighting at the end of each line onto the start of the next
  • Shift Left Mouse Drag - same as standard left drag
  • Ctrl Left Mouse Drag - Highlights all the whole words between the starting word and the ending word, also wrapping at line ends
  • Alt Left Mouse Drag - Highlights the text in a rectangle regardless of the shape and structure of the lines you are highlighting. When you start editing it replaces the highlighted block but is intelligent enough to make the same replacement on every line highlighted! You can even highlight a zero character width area to perform an insert when you start typing!!
  • Arrow Keys - position cursor (again, obviously)
  • Shift Arrow Keys - highlight text between the original cursor position and the new one
  • Ctrl Arrow Keys - scroll the screen up and down or jump the cursor word by word left and right
  • Alt Arrow Keys - Move the current line or highlighted text up or down relating to the rest of the text!

Sadly the fun ends there because right mouse clicking opens a context menu and absolutely zip all else.



Thursday, 8 June 2017

Powershell & Downloaded Scripts

We've changed the way we build and package our BizTalk apps using Visual Studio Team Service. We used to build our MSI's, bindings and PowerShell deployment scripts and then zip them all into a single Deploy.ZIP package on our on site build server. Now we leave the MSI's, bindings and PowerShell scripts in the Artifacts folder in the cloud, ready for a Release to deploy them.

So today I've downloaded the artifacts for the first time. Chrome has kindly downloaded Artifacts.ZIP for me ready for use. I've unzipped it and copied the contents to my target server. I've then run my deployment PowerShell script.

Well blow me, PowerShell has noticed my files have been download from the internet and now asks me if I trust each and every script! Worse, even if I say I would like to (R)un Once for each script they no longer work because various PowerShell commands are unavailable.

The workaround is simple.

Download the zip file from the Artifacts location. Then open Properties on the zip file. Check the "Unblock" checkbox and click OK. Now you can unzip as normal.

Behold, the extracted files are no longer being considered a top security risk. The prompt goes away and suddenly you are able to run commandlets again. Life is good, but...

What we do is hard.