Thursday, May 26, 2016

Provisioning Virtual Directories using ARM Template in Azure

This is as much a means to record what to do as to post a blog, but I recently ran into a requirement to deploy web packages to an Azure Web App using MSDeploy where the packages were to be uploaded to virtual directories/applications. The web app was being deployed using Azure Resource Manager (ARM) and I was struggling to find the correct syntax on how to define these directories.

After some searching I found this answer from David Ebbo with a PowerShell way of doing the same thing and wandered if I might modify this to work inside an ARM template.

https://social.msdn.microsoft.com/Forums/azure/en-US/990f41fd-f8b6-43a0-b942-cef0308120b2/add-virtual-application-and-directory-to-an-azure-website-using-powershell?forum=windowsazurewebsitespreview#0435503d-032e-429d-93ff-e106be04f556

It turns out that you can and the answer is quite straight forward. Rather than using the PowerShell structure, define your 'props' as JSON instead and since this is deploying a resource type of 'Microsoft.Web/sites/config' the whole configuration struct can be placed inside your website section as follows:

{
"type": "Microsoft.Web/sites",
"name": "[variables('requestSiteName')]",
"apiVersion": "2015-08-01",
"location": "West Europe",
...
"properties": {
"name": "[variables('requestSiteName')]",
...
},
"dependsOn": [
...
],
"resources": [
{
...
},
{
"apiVersion": "2015-08-01",
"name": "web",
"type": "config",
"properties": {
"virtualApplications": [
{
"virtualPath": "/",
"physicalPath": "site\\wwwroot"
},
{
"virtualPath": "/foo",
"physicalPath": "site\\bar"
}
]
}
}
]
}

Monday, March 14, 2016

Updating Publishing Page attribute in SharePoint Online

We have moved over to using the Patterns and Practices approach to SharePoint site deployment, with the exception of a few older or more complex .wsp based sites and for one product we are using post-provisioning tasks to modify the values of a custom content type based on values passed through PnP by storing them in the property bag.

Initially, the site template we were using was a vanilla Team Site, however, it was deemed necessary to enable publishing to achieve certain goals. Once this was done, we needed to checkin/checkout/publish the page in order to make and save the changes. This was failing with the save operation complaining that the page was checked out. Initially I was shouting at SP because I knew the page was checked out, because I had asked for it to be, however, it seems that this wasn't the checkout SP was referring to.

Finding this post on Stack Overflow (http://sharepoint.stackexchange.com/questions/59177/check-out-update-then-check-in-a-file-in-sharepoint-client-object-model) it seems that the flow needs to be:

  • Check out
  • ExecuteQuery()
  • Modify
  • Update()
  • ExecuteQuery()
  • Checkin
  • Publish
  • ExecuteQuery()
When we did this the page was successfully updated. One thing that I additionally did was to wrap the checkout/executequery in a try/catch so that if the page was already checked out, it would carry on and run the update. However, this will probably only be a solution if the user who has the page checked out is the same as that running the current update.

Thursday, March 10, 2016

Credential Error with VS 2015 multiple accounts

Strange one, but I was trying to log in to my personal MSDN Azure subscription from Visual Studio 2015 in order to deploy a web app, something I've done many times before, and it asked me to refresh my credentials. However, every time I tried, I would receive the error

"We could not refresh credentials... multiple_matching_tokens_found" (or something along those lines, apologies I didn't get a screen shot).

So Googling I found the following issue which was closed as 'Not Reproducible', but in this case I could reproduce, and I followed the suggestions.

https://connect.microsoft.com/VisualStudio/feedback/details/1052566/multiple-matching-tokens

Can you try one of the following workarounds to see if your issue is resolved?

1. Go to https://msdn.microsoft.com/en-us/library/vstudio/dn872465(v=vs.140).aspx, and follow the instructions described under "Add a second user account to Visual Studio" to open the Visual Studio Account Manager
2. In the Visual Studio Account Manager, remove the accounts used to access the affected Azure subscriptions shown under the "All Accounts" section of the dialog
3. Re-add the accounts you had just removed
4. Close the Visual Studio Account Manager
5. Try using your Azure subscription again

If that does not resolve your issue:

1. Close Visual Studio
2. Open the Windows File Explorer
3. Go to %USERPROFILE%\AppData\Local\Microsoft\VSCommon\VSAccountManagement
4. Rename or delete the AdalCache.cache file
5. Restart Visual Studio
6. Try using your Azure subscription again, and enter your account credentials if prompted

For me, the second option, deleting the credential cache worked.

I just wanted to record this somewhere as there are obviously some people suffering from this but it's unlikely to be solved.

PowerShell Script with full path

One of those banging your head one the wall problems today, with trying to run a PS script that I needed to supply the full path and where the path had spaces.

PS C:\>C:\My Scripts\My PowerShell.ps1

Now I knew that wouldn't work, but tried it anyway. Get the error

The term 'C:\My' is not recognized as the name of a cmdlet, function, script file, or operable program.

So I think, ok, let's wrap in quotes. That'll work

PS C:\>"C:\My Scripts\My PowerShell.ps1"

But nothing. No error, no nothing...hmmm

Some Googling later, as with PS scripts that don't need a space, you need to pre-fix with .\, if they are wrapped in quotes, you need to prefix with '&' (obviously). I expect it is obvious to those that work in PS all the time, but I don't...

So the command I was really looking for is

PS C:\>& "C:\My Scripts\My PowerShell.ps1"

Wednesday, March 9, 2016

Visual Studio and Auto-Format of SharePoint aspx

I was working on an aspx layout page for SharePoint and foolishly, it would appear, selected 'Format Document' from the Edit > Advanced fly out in VS 2015. Deploying the layout template stopped working and it transpired that the reason was because of the 'Format Document' command.

Despite both SharePoint and Visual Studio being MS products and .aspx a MS file extension, the command in VS breaks it. Nice work!

So what happened?

Well, it seems that formatting the document modifies the casing of certain aspx tags and turns

<asp:Content ContentPlaceHolderId=

into

<asp:content contentplaceholderid=

And that, it seems is not liked by SharePoint. The solution is a quick search and replace (be careful with that) and the layout works like it always did. 

Wednesday, February 3, 2016

Stop Worrying and Love Redmond

So, this is my first post on my 'new' blog about living with Microsoft. In fact, not just living with, but learning to stop worrying and love Redmond. Just to clarify, I do not work for Microsoft, this blog is a personal view on coming back to the MS technology stack after many years.

The purpose of this introductory post is to say that while I have been 'forced' into a much more Microsoft world than I previously occupied, what I am discovering is that the MS of old is being replaced, quickly, by a very different animal. And whilst I continue to keep hold of my sceptical-at-best attitude to the all mighty SharePoint, I have to say that my head has been well and truly turned by both Office 365 and Azure and in particular the latter.

I used to hold the opinion (and I feel it was very justified) that MS wanted to dominate across every arena into which they ventured. Stories I have heard certainly seem to back that up. And dominate they did. Dominance comes with a price, you were either with them or against them. You either dived right in to the bucket of kool-aid and focused on what MS told you, or you ventured elsewhere. I didn't dive in, I never liked having things forced upon me. I don't like to be sucked in to a technology where I no longer have choice, at that was how I viewed MS. From languages to applications, you were either on Windows or you walked.

But that was then.

But over the past couple of years I became aware that I was responding so the various announcements coming out of Redmond with some enthusiasm. Visual Studio Code, for you Mac or Linux machine; Visual Studio Online (now Team Services) supporting builds that run on xCode; a single Windows runtime and API across all devices; Docker support in Azure. The list was long and unusually breached the MS product boundary. It was exciting.

Where MS went, so I was destined to follow. The company I was working for had made the decision to go all out MS Cloud. The stack was very heavy on SharePoint but with a requisite amount of Azure and Office 365 thrown in for good measure. The more I dug into Azure and the more I worked with Office 365, the more I understood (or thought I did) where MS are heading. And the more I find myself impressed and excited about what will happen next.

So, that's my starting point. My view may change, MS might disappoint (in fact they're bound to), but I hope that the direction remains. It's exciting to think about where they might go and what they might do and I look forward to reporting my thoughts and experiences in the months ahead.

For now, that's all I have.