Thursday, July 7, 2016

Updating NuGet extension on Visual Studio 2015

NuGet is pretty awesome, though for some reason the NuGet Package Manager for Visual Studio 2015 extension was re-done and every time I try to update it I get an error, and then the extension seems to not work when restarting Visual Studio.
Took quite a while to figure out why, but it seems that it's to do with not being able to uninstall the old version of the extension. Extensions are installed into the folder C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions (or similar depending on the VS version). Certain folders in this path relate to an extension per folder, those that look like randomly generated names specifically, as below:
404 - Image Not Found
Each time the NuGet extension tried to update, it would fail to remove the old installation, and then create a new folder for the 'upgrade'. If you tried to upgrade it a few times, you may have quite a few folders that contain the NuGet extension. When you restart VS it seems to have issues loading the extension because of this. Go through each of these to find those folders, e.g.:
404 - Image Not Found
Close Visual Studio, and then delete each of those folders specific to the NuGet extension. Then manually download the VSIX extension installer from the website, and install it outside of Visual Studio. Once complete, start up Visual Studio and the extension should be installed properly. Whether it works or not is another thing, it seems the GUI is quite buggy with this extension, so I prefer using the Package Manager Console.
Hope this helps someone, I've had to come back to doing this a few times, so it'll definitely help me in future I'm sure :D

Friday, March 18, 2016

Set up IIS using PowerShell

When you're setting up a new server there are sometimes steps you need to do before you can configure your website, such as turning on Windows Authentication in corporate environments, or perhaps installing the features necessary for an ASP.NET application. I had to do this recently when setting up new servers at a client:
404 - Image Not Found
404 - Image Not Found
404 - Image Not Found
There was this final screen though where I noticed that this configuration can be exported to an XML file and set up via PowerShell. When inspecting the XML that was generated however, it seemed to include specific host names and so may not be a very generic way of setting up a server. After a bit of investigation, there are other commands that one can run to view what is installed, as well as install specific features.
404 - Image Not Found
404 - Image Not Found
Notice too that it seems to install other dependent features by default, as I just specified ASP.NET 4.5 but the other related features were also installed (in the GUI version you would be prompted about this).
Could be quite useful to have this as a script instead of remembering which features to turn on and off. My PowerShellFu isn’t the strongest, but something along the lines of this should work (I formatted this on separate lines for readability, you will want to run it as a single line):

Get-WindowsFeature -Name Web-*
  | Where-Object
  {
    ($_.Name -eq "Web-Asp-Net45" -or $_.Name -eq "Web-Windows-Auth")
    -and
    $_.InstallState -ne "Installed"
  }
  | Install-WindowsFeature

This may be a bit more generic, and could be used as a script included in source control for setting up new servers, instead of manually doing this via the Server Manager. There are also more advanced options to the cmdlets, more information of which can be seen in the documentation, one example of which is specifying a ComputerName.
One scenario I could think of for this is when setting up a web farm, and perhaps you have multiple hosts you need to do this on. Instead of doing each separately, you could probably pipe in the hostnames to a setup script, and let it perform the setup on each host. Though, as said, my PowerShellFu isn't strong, and I've had issues setting up remote PowerShell admin before, so I'll leave that part up to you ;)