Upgrade your apps to Windows 8.1 – Tips and tricks

So Windows 8.1 has been out for a while now. For newly written apps the default target is already Windows 8.1. But what about the older apps?

Microsoft gives you a solution which, while not perfect, is very useful. All you have to do is press and click.

Retarget

Retargeting an app from windows 8 to 8.1 is very simple: right click the Project and hit Retarget to Windows 8.1

A small panel shows up telling you that you should back up, blah blah blah. If you use version control like TFS, the best way to back up is to check in before retargeting

Hit OK to let Visual Studio do the Retarget

When you see this panel, you’re halfway there

Fix errors and Warning

As you can see in the picture above, plenty of Errors and Warnings show up. Don’t worry — once you build the project you’ll see even more errors

The References errors

As in the picture above, the old app uses the Microsoft Advertising SDK for Windows 8 (XAML) version 6.1. Since you upgraded to 8.1, you have to use a newer SDK version.

Right click Reference in the Project Folder, pick Add Reference…

Uncheck the grayed-out rows and check the matching bright ones, like in the picture below. Once done, hit OK

Reinstall Nuget Package

Some Nuget Packages still refuse to target Windows 8.1. We’ll retarget them by…reinstalling

Open Tool > Nuget Package Manager > Package Manager Console

There is an option that lets you Reinstall every nuget package, but that takes a while. You should only update the affected packages. The name of the affected Package is in the error message

Type the following command. The last bit is the package name

The Package Manager Console runs, looking very professional :3

Note: when reinstalling the Google Analytics SDK you’ll see a file conflict. Type N so it skips overwriting that file.

Do the same for the other packages. This time you just hit the arrow key to paste the previous command back. Edit the package name and you’re done

Fixing the Resource warning

Those of you building Multiple language apps will hit this warning. The reason is that the GetValue method has been obsoleted, so you need a small upgrade

Very simple. Add “ResourceContext.GetForCurrentView()” as the 2nd parameter and that’s it

Change it to this

Fixing the query for Windows Size directly error

In windows 8.1 the window size can be read directly. So this line in the Layout Aware Page is out of date.

We fix it by fixing the DetermineVisualState method

Right click DetermineVisualState > Go to Definition

Change it to this

protected virtual string DetermineVisualState()
{
    string visualState = "FullScreenLandscape";
    var windowWidth = Window.Current.Bounds.Width;
    var windowHeight = Window.Current.Bounds.Height;
    if (windowWidth <= 500)
    {
        visualState = "Snapped" + "_Detail";
    }
    else if (windowWidth <= 1366)
    {
        if (windowWidth < windowHeight)
        {
            visualState = "FullScreenPortrait" + "_Detail";
        }
        else
        {
            visualState = "FilledOrNarrow";
        }
    }
    return visualState;
}

Then replace the old method with this one. Note that this method takes no parameters

That’s it. Build again and you’ll see there are no errors left :yay: