<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
        <title>Code Inside Blog</title>
        <description>Code Inside Blog - Code Inside Team</description>
        <link>https://oliverguhr.github.io/Blog/</link>
        <link>https://oliverguhr.github.io/Blog/</link>
        <lastBuildDate>Wed, 03 Apr 2024 11:22:39 +0000</lastBuildDate>
        <pubDate>Wed, 03 Apr 2024 11:22:39 +0000</pubDate>
        <ttl>1800</ttl>


        <item>
                <title>Using Visual Studio Code &amp; Team Foundation Version Control (TFVC)</title>
                <description>
&lt;p&gt;Recently we start working on a Angular 4 app but all other parts of the application (e.g. the backend stuff) were stored in a good old TFVC based repository (inside a Team Foundation Server 2015) . 
Unfortunately building an Angular app with the full blown Visual Studio with the “default” Team Explorer workflow is not really practical.
Another point for using Visual Studio Code was that most other online resources about learning Angular are using VS Code.&lt;/p&gt;

&lt;p&gt;Our goal was to keep &lt;strong&gt;one&lt;/strong&gt; repository, otherwise it would be harder to build and maintain.&lt;/p&gt;

&lt;h2 id=&quot;first-plan-migrate-to-git&quot;&gt;First plan: Migrate to Git&lt;/h2&gt;

&lt;p&gt;First we tried to migrate our &lt;strong&gt;complete&lt;/strong&gt; code base to Git with this &lt;a href=&quot;https://github.com/git-tfs/git-tfs&quot;&gt;generally awesome tool&lt;/a&gt;. Unfortunately for us it failed because of our quite large branch-tree. I tried it on a smaller code base and it worked without any issues.&lt;/p&gt;

&lt;p&gt;At this point we needed another solution, because we wanted to get started on the actual application - so we tried to stick with TFVC.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; I always would recommend Git over TFVC, because it’s the way our industry is currently moving and at some point in the future we will do this too.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you have similar problems like us: Read on!&lt;/strong&gt;&lt;/p&gt;

&lt;h2 id=&quot;second-plan-get-the-tfvc-plugin-working-in-visual-studio-code&quot;&gt;Second plan: Get the TFVC plugin working in Visual Studio Code&lt;/h2&gt;

&lt;p&gt;Good news: Since &lt;a href=&quot;https://blogs.msdn.microsoft.com/visualstudioalm/2017/04/12/official-release-of-tfvc-support-for-visual-studio-code/&quot;&gt;April 2017&lt;/a&gt; there is a Visual Studio Team Services extension for Visual Studio Code that also supports TFVC!&lt;/p&gt;

&lt;p&gt;Requirements:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Team Foundation Server 2015 Update 2&lt;/li&gt;
  &lt;li&gt;A existing &lt;strong&gt;local&lt;/strong&gt; workspace configuration (at least currently, check this &lt;a href=&quot;https://github.com/Microsoft/vsts-vscode/issues/176&quot;&gt;GitHub issue&lt;/a&gt; for further information)&lt;/li&gt;
  &lt;li&gt;The actual &lt;a href=&quot;https://github.com/Microsoft/vsts-vscode&quot;&gt;extension&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;be-aware-local-workspaces&quot;&gt;Be aware: Local Workspaces!&lt;/h2&gt;

&lt;p&gt;Even I’m using TFS since a couple of years I just recently discovered that the TFS supports to different “workflows”. The “default” workflow always needs a connection to the TFS to checkout files etc. 
There is an alternative mode called “local” mode which seems to work like SVN. The difference is, that you can create a local file and the TFVC-client will “detect” those changes. Read more about the differences &lt;a href=&quot;https://www.visualstudio.com/en-us/docs/tfvc/decide-between-using-local-server-workspace&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2017-05-29/local-workspace.png&quot; alt=&quot;x&quot; title=&quot;Local Workspace setting&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;configuration&quot;&gt;Configuration&lt;/h2&gt;

&lt;p&gt;In our OnPremise TFS 2015 world I just needed only this configuration line in my user settings:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;...
&quot;tfvc.location&quot;: &quot;C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\TF.exe&quot;,
...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;action&quot;&gt;Action!&lt;/h2&gt;

&lt;p&gt;Now when I point VS Code to my local workspace folder, the TFVC plugin will kick in and I see the familiar “change”-tracking:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2017-05-29/changetracking.png&quot; alt=&quot;x&quot; title=&quot;Working with the extension&quot; /&gt;&lt;/p&gt;

&lt;p&gt;It is not perfect, because I still need to setup and “manage” (e.g. get the history etc.) via the full blown Visual Studio, but with this setup it is “do-able”.&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2017/05/29/using-vscode-and-tfvc/</link>
                <guid>https://oliverguhr.github.io/Blog//2017/05/29/using-vscode-and-tfvc</guid>
                <pubDate>Mon, 29 May 2017 23:45:00 +0000</pubDate>
        </item>

        <item>
                <title>.NET CultureInfo in Windows 10</title>
                <description>
&lt;p&gt;Did you know that the CultureInfo behavior with &lt;strong&gt;“unkown”&lt;/strong&gt; cultures has changed with Windows 10?&lt;/p&gt;

&lt;p&gt;I stumbled two times about this “problem” - so this is enough to write a short blogpost about it.&lt;/p&gt;

&lt;h2 id=&quot;demo-code&quot;&gt;Demo Code&lt;/h2&gt;

&lt;p&gt;Lets use this democode:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    try
    {


        // ok on Win10, but not on pre Win10 if culture is not registred
        CultureInfo culture1 = new CultureInfo(&quot;foo&quot;);
        CultureInfo culture2 = new CultureInfo(&quot;xyz&quot;);
        CultureInfo culture3 = new CultureInfo(&quot;en-xy&quot;);

        // not ok even on Win 10 - exception
        CultureInfo culture4 = new CultureInfo(&quot;foox&quot;);

    }
    catch (Exception exc)
    {

    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;windows-10-case&quot;&gt;Windows 10 Case&lt;/h2&gt;

&lt;p&gt;If you run this code under Windows 10 it should fail for the “foox” culture, because it doesn’t seem to be a valid culture anyway.&lt;/p&gt;

&lt;p&gt;“culture1”, “culture2”, “culture3” are all &lt;strong&gt;valid&lt;/strong&gt; cultures in the Windows 10 world, but are resolved with &lt;strong&gt;Unkown Locale&lt;/strong&gt; and &lt;strong&gt;LCID 4096&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I guess Windows will look for a 2 or 3 letter ISO style language, and “foox” doesn’t match this pattern.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;pre-windows-10---eg-running-on-win-server-2012r2&quot;&gt;Pre Windows 10 - e.g. running on Win Server 2012R2&lt;/h2&gt;

&lt;p&gt;If you would run the code unter Windows Server 2012 R2 it would fail on the first culture, because there is no “foo” culture registred.&lt;/p&gt;

&lt;h2 id=&quot;problem&quot;&gt;“Problem”&lt;/h2&gt;

&lt;p&gt;The main “problem” is that this behavior could lead to some production issues if you develop with Windows 10 and the software is running on a Win 2012 server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If&lt;/strong&gt; you are managing “language” content in your application, be aware of this “limitation” on older Windows versions.&lt;/p&gt;

&lt;p&gt;I discovered this problem while debugging our backend admin application. With this ASP.NET frontend it is possible to add or manage “localized” content and the dropdown for the possible language listed a whole bunch of very special, but “Unkown locale” cultures. So we needed to filter out all LCID 4096 cultures to ensure it would run under all Windows versions.&lt;/p&gt;

&lt;h2 id=&quot;msdn&quot;&gt;MSDN&lt;/h2&gt;

&lt;p&gt;This behavior is also documented on &lt;strong&gt;&lt;a href=&quot;https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.lcid%28v=vs.110%29.aspx?f=255&amp;amp;MSPPError=-2147217396&quot;&gt;MSDN&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;&lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/dd373745(v=vs.85).aspx&quot;&gt;“Unkown culture” LCID 4096&lt;/a&gt;&lt;/strong&gt; was introduced with Windows Vista, but only with Windows 10 it will be “easy” usable within the .NET Framework.&lt;/p&gt;

</description>
                <link>https://oliverguhr.github.io/Blog//2017/04/23/net-cultureinfo-in-windows10/</link>
                <guid>https://oliverguhr.github.io/Blog//2017/04/23/net-cultureinfo-in-windows10</guid>
                <pubDate>Sun, 23 Apr 2017 23:45:00 +0000</pubDate>
        </item>

        <item>
                <title>How we moved to Visual Studio 2017</title>
                <description>
&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2017-03-28/vs.png&quot; alt=&quot;x&quot; title=&quot;VS 2017 installer&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Visual Studio 2017 has arrived and because of .NET Core and other goodies we wanted to switch fast to the newest release with our product &lt;a href=&quot;http://oneoffixx.com/&quot;&gt;OneOffixx&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;company--product-environment&quot;&gt;Company &amp;amp; Product Environment&lt;/h2&gt;

&lt;p&gt;In our solution we use some VC++ projects (just for Office Development &amp;amp; building a .NET shim), Windows Installer XML &amp;amp; many C# projects for desktop or ASP.NET stuff.&lt;/p&gt;

&lt;p&gt;Our builds are scripted with &lt;strong&gt;&lt;a href=&quot;http://cakebuild.net&quot;&gt;CAKE&lt;/a&gt;&lt;/strong&gt; (see here for some more blogposts about [CAKE}(https://blog.codeinside.eu/2017/02/13/create-nuget-packages-with-cake/) and us the TFS vNext Build to orchestrate everything.&lt;/p&gt;

&lt;h2 id=&quot;step-1-update-the-development-workstations&quot;&gt;Step 1: Update the Development Workstations&lt;/h2&gt;

&lt;p&gt;The first step was to update my local dev enviroment and install Visual Studio 2017.&lt;/p&gt;

&lt;p&gt;After the installation I started VS and opened our solution and because we have some WIX projects we needed the most recent &lt;strong&gt;&lt;a href=&quot;http://wixtoolset.org/releases/&quot;&gt;Wix 3.11 toolset &amp;amp; the VS 2017 extension&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;step-2-vc-update&quot;&gt;Step 2: VC++ update&lt;/h2&gt;

&lt;p&gt;We wanted a clean VS 2017 enviroment, so we decided to use the most recent &lt;strong&gt;VC++ 2017 runtime&lt;/strong&gt; for our VC++ projects.&lt;/p&gt;

&lt;h2 id=&quot;step-3-project-update&quot;&gt;Step 3: project update&lt;/h2&gt;

&lt;p&gt;In the past we had some issues that MSBuild used the wrong MSBuild version. Maybe this step is not needed, but we pointed all .csproj files to the newest &lt;strong&gt;MSBuild ToolVersion 15.0&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;step-4-cake-update&quot;&gt;Step 4: CAKE update&lt;/h2&gt;

&lt;p&gt;The last step was to update the CAKE.exe (which is controlled by us and not automatically downloaded via a build script) to 0.18.&lt;/p&gt;

&lt;h2 id=&quot;step-5-minor-build-script-changes&quot;&gt;Step 5: Minor build script changes&lt;/h2&gt;

&lt;p&gt;We needed to adjust some paths (e.g. to the Windows SDK for signtool.exe) and ensure that we are using the most recent MSBuild.exe.&lt;/p&gt;

&lt;h2 id=&quot;step-6-create-a-new-build-agent&quot;&gt;Step 6: Create a new Build-Agent&lt;/h2&gt;

&lt;p&gt;We decided to create a &lt;strong&gt;&lt;a href=&quot;https://blog.codeinside.eu/2016/08/10/adding-a-new-windowsagent-to-tfs2015-build/&quot;&gt;new TFS Build-Agent&lt;/a&gt;&lt;/strong&gt; and do the usual build agent installation, imported the code-cert and do some magic because of some C++/COM-magic (don’t ask… COM sucks.)&lt;/p&gt;

&lt;h2 id=&quot;recap&quot;&gt;Recap&lt;/h2&gt;

&lt;p&gt;Besides the C++/COM/magic issue (see above) the migration was pretty easy and now our team works with Visual Studio 2017.&lt;/p&gt;

</description>
                <link>https://oliverguhr.github.io/Blog//2017/03/27/how-we-moved-to-vs-2017/</link>
                <guid>https://oliverguhr.github.io/Blog//2017/03/27/how-we-moved-to-vs-2017</guid>
                <pubDate>Mon, 27 Mar 2017 23:45:00 +0000</pubDate>
        </item>

        <item>
                <title>HowTo: Get User Information &amp; Group Memberships from Active Directory via C#</title>
                <description>
&lt;p&gt;I had to find a way to access all group memberships from a given Active Directory user. The problem here is, that groups may contain other groups and I needed a list of “all” applied group memberships - directly or indirectly.&lt;/p&gt;

&lt;p&gt;The “fastest” solution (without querying each group) is to use the &lt;strong&gt;&lt;a href=&quot;https://msdn.microsoft.com/en-us/library/ms680275(v=vs.85).aspx&quot;&gt;Token-Groups attribute&lt;/a&gt;&lt;/strong&gt;, which already does this magic for us. 
This list should contain &lt;strong&gt;all&lt;/strong&gt; applied groups.&lt;/p&gt;

&lt;p&gt;The code would also allow to read any other AD property, e.g. the UPN or names etc.&lt;/p&gt;

&lt;h2 id=&quot;code&quot;&gt;Code&lt;/h2&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(&quot;ListAllGroupsViaTokenGroups:&quot;);

        List&amp;lt;string&amp;gt; result = new List&amp;lt;string&amp;gt;();

        try
        {
            result = ListAllGroupsViaTokenGroups(&quot;USERNAME&quot;, &quot;DOMAIN&quot;);

            foreach (var group in result)
            {
                Console.WriteLine(group);
            }
        }
        catch (Exception exc)
        {
            Console.WriteLine(exc.Message);
        }

        Console.Read();
    }

  
    private static List&amp;lt;string&amp;gt; ListAllGroupsViaTokenGroups(string username, string domainName)
    {
        List&amp;lt;string&amp;gt; result = new List&amp;lt;string&amp;gt;();

        using (PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, domainName))
        using (var searcher = new DirectorySearcher(new DirectoryEntry(&quot;LDAP://&quot; + domainContext.Name)))
        {
            searcher.Filter = String.Format(&quot;(&amp;amp;(objectClass=user)(sAMAccountName={0}))&quot;, username);
            SearchResult sr = searcher.FindOne();

            DirectoryEntry user = sr.GetDirectoryEntry();

            // access to other user properties, via user.Properties[&quot;...&quot;]

            user.RefreshCache(new string[] { &quot;tokenGroups&quot; });

            for (int i = 0; i &amp;lt; user.Properties[&quot;tokenGroups&quot;].Count; i++)
            {
                SecurityIdentifier sid = new SecurityIdentifier((byte[])user.Properties[&quot;tokenGroups&quot;][i], 0);
                NTAccount nt = (NTAccount)sid.Translate(typeof(NTAccount));

                result.Add(nt.Translate(typeof(NTAccount)).ToString() + &quot; (&quot; + sid + &quot;)&quot;);
            }
        }

        return result;
    }

}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Hope this will help someone in the future.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://github.com/Code-Inside/Samples/tree/master/2017/ADLookupWithGroups&quot;&gt;Code @ GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2017/03/02/howto-get-user-information-and-groups-from-ad/</link>
                <guid>https://oliverguhr.github.io/Blog//2017/03/02/howto-get-user-information-and-groups-from-ad</guid>
                <pubDate>Thu, 02 Mar 2017 23:45:00 +0000</pubDate>
        </item>

        <item>
                <title>Create NuGet packages with Cake</title>
                <description>
&lt;p&gt;This blogpost is a follow up to these &lt;strong&gt;&lt;a href=&quot;http://cakebuild.net/&quot;&gt;Cake (C# Make)&lt;/a&gt;&lt;/strong&gt; related blogpost:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://blog.codeinside.eu/2016/07/09/cake-building-with-cake/&quot;&gt;Building with Cake&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://blog.codeinside.eu/2017/02/07/build-and-run-xunit-tests-with-cake/&quot;&gt;Build &amp;amp; run xUnit tests with Cake&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;scenario&quot;&gt;Scenario&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2017-02-13/proj.png&quot; alt=&quot;x&quot; title=&quot;Demo proj&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Let’s say we have this project structure. The “Config”, “Result” and “Engine” projects contains a corresponding .nuspec, like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;?xml version=&quot;1.0&quot;?&amp;gt;
&amp;lt;package &amp;gt;
  &amp;lt;metadata&amp;gt;
    &amp;lt;id&amp;gt;Sloader.Config&amp;lt;/id&amp;gt;
    &amp;lt;version&amp;gt;$version$&amp;lt;/version&amp;gt;
    &amp;lt;title&amp;gt;Sloader.Config&amp;lt;/title&amp;gt;
    &amp;lt;authors&amp;gt;Code Inside Team&amp;lt;/authors&amp;gt;
    &amp;lt;owners&amp;gt;Code Inside Team&amp;lt;/owners&amp;gt;
    &amp;lt;licenseUrl&amp;gt;https://github.com/Code-Inside/Sloader/blob/master/LICENSE&amp;lt;/licenseUrl&amp;gt;
    &amp;lt;projectUrl&amp;gt;https://github.com/Code-Inside/Sloader&amp;lt;/projectUrl&amp;gt;
    &amp;lt;requireLicenseAcceptance&amp;gt;false&amp;lt;/requireLicenseAcceptance&amp;gt;
    &amp;lt;description&amp;gt;Sloader Config&amp;lt;/description&amp;gt;
    &amp;lt;releaseNotes&amp;gt;
      ## Version 0.1 ##
      Init
    &amp;lt;/releaseNotes&amp;gt;
    &amp;lt;copyright&amp;gt;Copyright 2017&amp;lt;/copyright&amp;gt;
    &amp;lt;tags&amp;gt;Sloader&amp;lt;/tags&amp;gt;
    &amp;lt;dependencies /&amp;gt;
  &amp;lt;/metadata&amp;gt;
&amp;lt;/package&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Nothing fancy - pretty normal NuGet stuff, but be aware of the “$version$” variable. This variable is called a &lt;a href=&quot;https://docs.microsoft.com/de-de/nuget/schema/nuspec#replacement-tokens&quot;&gt;“replacement-token”&lt;/a&gt;. When the NuGet package is created and it detects such a replacement-token, it will search for the AssemblyVersion (or other replacement-token sources).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Versioning in NuGet:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I’m not a NuGet expert, but you should also versioning your assembly info, otherwise some systems may have trouble to update your dll. The version inside the package can be different from the actual assembly version, but you should manage booth or use this replacement-token-mechanic.&lt;/p&gt;

&lt;h2 id=&quot;goal&quot;&gt;Goal&lt;/h2&gt;

&lt;p&gt;The goal is to create a NuGet package for each target project with Cake.&lt;/p&gt;

&lt;h2 id=&quot;buildcake&quot;&gt;build.cake&lt;/h2&gt;

&lt;p&gt;The usage in Cake is pretty much the same as with the normal &lt;strong&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/nuget/tools/nuget-exe-cli-reference#pack&quot;&gt;nuget.exe pack&lt;/a&gt;&lt;/strong&gt; command 
The sample only shows the actual cake target - see the older blogposts for a more complete example:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Task(&quot;BuildPackages&quot;)
    .IsDependentOn(&quot;Restore-NuGet-Packages&quot;)
	.IsDependentOn(&quot;RunTests&quot;)
    .Does(() =&amp;gt;
{
    var nuGetPackSettings = new NuGetPackSettings
	{
		OutputDirectory = rootAbsoluteDir + @&quot;\artifacts\&quot;,
		IncludeReferencedProjects = true,
		Properties = new Dictionary&amp;lt;string, string&amp;gt;
		{
			{ &quot;Configuration&quot;, &quot;Release&quot; }
		}
	};

    MSBuild(&quot;./src/Sloader.Config/Sloader.Config.csproj&quot;, new MSBuildSettings().SetConfiguration(&quot;Release&quot;));
    NuGetPack(&quot;./src/Sloader.Config/Sloader.Config.csproj&quot;, nuGetPackSettings);
    MSBuild(&quot;./src/Sloader.Result/Sloader.Result.csproj&quot;, new MSBuildSettings().SetConfiguration(&quot;Release&quot;));
    NuGetPack(&quot;./src/Sloader.Result/Sloader.Result.csproj&quot;, nuGetPackSettings);
    MSBuild(&quot;./src/Sloader.Engine/Sloader.Engine.csproj&quot;, new MSBuildSettings().SetConfiguration(&quot;Release&quot;));
    NuGetPack(&quot;./src/Sloader.Engine/Sloader.Engine.csproj&quot;, nuGetPackSettings);
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Easy, right? The most interesting part here is the &lt;a href=&quot;http://cakebuild.net/api/Cake.Common.Tools.NuGet/NuGetAliases/EF4ED944&quot;&gt;NuGetPack&lt;/a&gt; command. Before we invoke this command we need to make sure that we build the last recent version - to enforce that we just rebuild each project in release mode.&lt;/p&gt;

&lt;h2 id=&quot;result&quot;&gt;Result&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2017-02-13/result.png&quot; alt=&quot;x&quot; title=&quot;NuGet packages!&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The console output should make the flow pretty clear:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;PS C:\Users\Robert\Documents\GitHub\Sloader&amp;gt; .\build.ps1 -t BuildPackages
Preparing to run build script...
Running build script...
Analyzing build script...
Processing build script...
Installing tools...
Compiling build script...

========================================
Clean
========================================
Executing task: Clean
Cleaning directory C:/Users/Robert/Documents/GitHub/Sloader/artifacts
Finished executing task: Clean

========================================
Restore-NuGet-Packages
========================================
Executing task: Restore-NuGet-Packages
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
All packages listed in packages.config are already installed.
Finished executing task: Restore-NuGet-Packages

========================================
BuildTests
========================================
Executing task: BuildTests
Start Building Test: Sloader.Config.Tests
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.

  Sloader.Config -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\artifacts\_tests\Sloader.Config.Tests\Sloader.Config.dll
  Sloader.Config.Tests -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\artifacts\_tests\Sloader.Config.Tests\Sloader.Config
  .Tests.dll
Start Building Test: Sloader.Result.Tests
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.

  Sloader.Result -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\artifacts\_tests\Sloader.Result.Tests\Sloader.Result.dll
  Sloader.Result.Tests -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\artifacts\_tests\Sloader.Result.Tests\Sloader.Result
  .Tests.dll
Start Building Test: Sloader.Engine.Tests
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.

  Sloader.Config -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\artifacts\_tests\Sloader.Engine.Tests\Sloader.Config.dll
  Sloader.Result -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\artifacts\_tests\Sloader.Engine.Tests\Sloader.Result.dll
  Sloader.Engine -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\artifacts\_tests\Sloader.Engine.Tests\Sloader.Engine.dll
  Sloader.Engine.Tests -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\artifacts\_tests\Sloader.Engine.Tests\Sloader.Engine
  .Tests.dll
Finished executing task: BuildTests

========================================
RunTests
========================================
Executing task: RunTests
Start Running Tests
xUnit.net Console Runner (64-bit .NET 4.0.30319.42000)
  Discovering: Sloader.Config.Tests
  Discovered:  Sloader.Config.Tests
  Starting:    Sloader.Config.Tests
  Finished:    Sloader.Config.Tests
  Discovering: Sloader.Engine.Tests
  Discovered:  Sloader.Engine.Tests
  Starting:    Sloader.Engine.Tests
  Finished:    Sloader.Engine.Tests
  Discovering: Sloader.Result.Tests
  Discovered:  Sloader.Result.Tests
  Starting:    Sloader.Result.Tests
  Finished:    Sloader.Result.Tests
=== TEST EXECUTION SUMMARY ===
   Sloader.Config.Tests  Total: 23, Errors: 0, Failed: 0, Skipped: 0, Time: 0.554s
   Sloader.Engine.Tests  Total: 17, Errors: 0, Failed: 0, Skipped: 0, Time: 1.070s
   Sloader.Result.Tests  Total:  4, Errors: 0, Failed: 0, Skipped: 0, Time: 1.061s
                                --          -          -           -        ------
                   GRAND TOTAL: 44          0          0           0        2.684s (5.697s)
Finished executing task: RunTests

========================================
BuildPackages
========================================
Executing task: BuildPackages
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 2017-02-19 22:00:09.
The target &quot;_ConvertPdbFiles&quot; listed in a BeforeTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Com
mon.targets\ImportAfter\Xamarin.Common.targets (34,37)&quot; does not exist in the project, and will be ignored.
The target &quot;_CollectPdbFiles&quot; listed in an AfterTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Com
mon.targets\ImportAfter\Xamarin.Common.targets (34,70)&quot; does not exist in the project, and will be ignored.
The target &quot;_CollectMdbFiles&quot; listed in a BeforeTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Com
mon.targets\ImportAfter\Xamarin.Common.targets (41,38)&quot; does not exist in the project, and will be ignored.
The target &quot;_CopyMdbFiles&quot; listed in an AfterTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common
.targets\ImportAfter\Xamarin.Common.targets (41,71)&quot; does not exist in the project, and will be ignored.
Project &quot;C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Config\Sloader.Config.csproj&quot; on node 1 (Build target(s))
.
GenerateTargetFrameworkMonikerAttribute:
Skipping target &quot;GenerateTargetFrameworkMonikerAttribute&quot; because all output files are up-to-date with respect to the i
nput files.
CoreCompile:
Skipping target &quot;CoreCompile&quot; because all output files are up-to-date with respect to the input files.
CopyFilesToOutputDirectory:
  Sloader.Config -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Config\bin\Release\Sloader.Config.dll
Done Building Project &quot;C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Config\Sloader.Config.csproj&quot; (Build target
(s)).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.22
Attempting to build package from 'Sloader.Config.csproj'.
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
Packing files from 'C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Config\bin\Release'.
Using 'Sloader.Config.nuspec' for metadata.
Found packages.config. Using packages listed as dependencies
Successfully created package 'C:\Users\Robert\Documents\GitHub\Sloader\artifacts\Sloader.Config.0.2.1.nupkg'.
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 2017-02-19 22:00:10.
The target &quot;_ConvertPdbFiles&quot; listed in a BeforeTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Com
mon.targets\ImportAfter\Xamarin.Common.targets (34,37)&quot; does not exist in the project, and will be ignored.
The target &quot;_CollectPdbFiles&quot; listed in an AfterTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Com
mon.targets\ImportAfter\Xamarin.Common.targets (34,70)&quot; does not exist in the project, and will be ignored.
The target &quot;_CollectMdbFiles&quot; listed in a BeforeTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Com
mon.targets\ImportAfter\Xamarin.Common.targets (41,38)&quot; does not exist in the project, and will be ignored.
The target &quot;_CopyMdbFiles&quot; listed in an AfterTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common
.targets\ImportAfter\Xamarin.Common.targets (41,71)&quot; does not exist in the project, and will be ignored.
Project &quot;C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Result\Sloader.Result.csproj&quot; on node 1 (Build target(s))
.
GenerateTargetFrameworkMonikerAttribute:
Skipping target &quot;GenerateTargetFrameworkMonikerAttribute&quot; because all output files are up-to-date with respect to the i
nput files.
CoreCompile:
Skipping target &quot;CoreCompile&quot; because all output files are up-to-date with respect to the input files.
CopyFilesToOutputDirectory:
  Sloader.Result -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Result\bin\Release\Sloader.Result.dll
Done Building Project &quot;C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Result\Sloader.Result.csproj&quot; (Build target
(s)).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.24
Attempting to build package from 'Sloader.Result.csproj'.
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
Packing files from 'C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Result\bin\Release'.
Using 'Sloader.Result.nuspec' for metadata.
Found packages.config. Using packages listed as dependencies
Successfully created package 'C:\Users\Robert\Documents\GitHub\Sloader\artifacts\Sloader.Result.0.2.1.nupkg'.
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 2017-02-19 22:00:12.
The target &quot;_ConvertPdbFiles&quot; listed in a BeforeTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Com
mon.targets\ImportAfter\Xamarin.Common.targets (34,37)&quot; does not exist in the project, and will be ignored.
The target &quot;_CollectPdbFiles&quot; listed in an AfterTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Com
mon.targets\ImportAfter\Xamarin.Common.targets (34,70)&quot; does not exist in the project, and will be ignored.
The target &quot;_CollectMdbFiles&quot; listed in a BeforeTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Com
mon.targets\ImportAfter\Xamarin.Common.targets (41,38)&quot; does not exist in the project, and will be ignored.
The target &quot;_CopyMdbFiles&quot; listed in an AfterTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common
.targets\ImportAfter\Xamarin.Common.targets (41,71)&quot; does not exist in the project, and will be ignored.
The target &quot;_ConvertPdbFiles&quot; listed in a BeforeTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Com
mon.targets\ImportAfter\Xamarin.Common.targets (34,37)&quot; does not exist in the project, and will be ignored.
The target &quot;_CollectPdbFiles&quot; listed in an AfterTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Com
mon.targets\ImportAfter\Xamarin.Common.targets (34,70)&quot; does not exist in the project, and will be ignored.
The target &quot;_CollectMdbFiles&quot; listed in a BeforeTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Com
mon.targets\ImportAfter\Xamarin.Common.targets (41,38)&quot; does not exist in the project, and will be ignored.
The target &quot;_CopyMdbFiles&quot; listed in an AfterTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common
.targets\ImportAfter\Xamarin.Common.targets (41,71)&quot; does not exist in the project, and will be ignored.
Project &quot;C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Engine\Sloader.Engine.csproj&quot; on node 1 (Build target(s))
.
Project &quot;C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Engine\Sloader.Engine.csproj&quot; (1) is building &quot;C:\Users\R
obert\Documents\GitHub\Sloader\src\Sloader.Config\Sloader.Config.csproj&quot; (2) on node 1 (default targets).
GenerateTargetFrameworkMonikerAttribute:
Skipping target &quot;GenerateTargetFrameworkMonikerAttribute&quot; because all output files are up-to-date with respect to the i
nput files.
CoreCompile:
Skipping target &quot;CoreCompile&quot; because all output files are up-to-date with respect to the input files.
CopyFilesToOutputDirectory:
  Sloader.Config -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Config\bin\Release\Sloader.Config.dll
Done Building Project &quot;C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Config\Sloader.Config.csproj&quot; (default targ
ets).

The target &quot;_ConvertPdbFiles&quot; listed in a BeforeTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Com
mon.targets\ImportAfter\Xamarin.Common.targets (34,37)&quot; does not exist in the project, and will be ignored.
The target &quot;_CollectPdbFiles&quot; listed in an AfterTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Com
mon.targets\ImportAfter\Xamarin.Common.targets (34,70)&quot; does not exist in the project, and will be ignored.
The target &quot;_CollectMdbFiles&quot; listed in a BeforeTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Com
mon.targets\ImportAfter\Xamarin.Common.targets (41,38)&quot; does not exist in the project, and will be ignored.
The target &quot;_CopyMdbFiles&quot; listed in an AfterTargets attribute at &quot;C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common
.targets\ImportAfter\Xamarin.Common.targets (41,71)&quot; does not exist in the project, and will be ignored.
Project &quot;C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Engine\Sloader.Engine.csproj&quot; (1) is building &quot;C:\Users\R
obert\Documents\GitHub\Sloader\src\Sloader.Result\Sloader.Result.csproj&quot; (3) on node 1 (default targets).
GenerateTargetFrameworkMonikerAttribute:
Skipping target &quot;GenerateTargetFrameworkMonikerAttribute&quot; because all output files are up-to-date with respect to the i
nput files.
CoreCompile:
Skipping target &quot;CoreCompile&quot; because all output files are up-to-date with respect to the input files.
CopyFilesToOutputDirectory:
  Sloader.Result -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Result\bin\Release\Sloader.Result.dll
Done Building Project &quot;C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Result\Sloader.Result.csproj&quot; (default targ
ets).

BclBuildEnsureBindingRedirects:
Skipping target &quot;BclBuildEnsureBindingRedirects&quot; because all output files are up-to-date with respect to the input file
s.
GenerateTargetFrameworkMonikerAttribute:
Skipping target &quot;GenerateTargetFrameworkMonikerAttribute&quot; because all output files are up-to-date with respect to the i
nput files.
CoreCompile:
Skipping target &quot;CoreCompile&quot; because all output files are up-to-date with respect to the input files.
_CopyAppConfigFile:
Skipping target &quot;_CopyAppConfigFile&quot; because all output files are up-to-date with respect to the input files.
CopyFilesToOutputDirectory:
  Sloader.Engine -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Engine\bin\Release\Sloader.Engine.dll
Done Building Project &quot;C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Engine\Sloader.Engine.csproj&quot; (Build target
(s)).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.54
Attempting to build package from 'Sloader.Engine.csproj'.
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
Packing files from 'C:\Users\Robert\Documents\GitHub\Sloader\src\Sloader.Engine\bin\Release'.
Using 'Sloader.Engine.nuspec' for metadata.
Found packages.config. Using packages listed as dependencies
Successfully created package 'C:\Users\Robert\Documents\GitHub\Sloader\artifacts\Sloader.Engine.0.2.1.nupkg'.
Finished executing task: BuildPackages

Task                          Duration
--------------------------------------------------
Clean                         00:00:00.1083837
Restore-NuGet-Packages        00:00:00.7808530
BuildTests                    00:00:02.6296445
RunTests                      00:00:05.9397822
BuildPackages                 00:00:05.2679058
--------------------------------------------------
Total:                        00:00:14.7265692
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2017/02/13/create-nuget-packages-with-cake/</link>
                <guid>https://oliverguhr.github.io/Blog//2017/02/13/create-nuget-packages-with-cake</guid>
                <pubDate>Mon, 13 Feb 2017 23:45:00 +0000</pubDate>
        </item>

        <item>
                <title>Build &amp; run xUnit tests with Cake</title>
                <description>
&lt;p&gt;Last year I already covered the &lt;strong&gt;&lt;a href=&quot;https://blog.codeinside.eu/2016/07/09/cake-building-with-cake/&quot;&gt;basic usage of Cake&lt;/a&gt;&lt;/strong&gt;, which stands for “C# Make”. This time we want to build and run &lt;strong&gt;&lt;a href=&quot;https://xunit.github.io/&quot;&gt;xUnit&lt;/a&gt;&lt;/strong&gt; tests with Cake.&lt;/p&gt;

&lt;h2 id=&quot;scenario&quot;&gt;Scenario&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2017-02-07/proj.png&quot; alt=&quot;x&quot; title=&quot;Demo proj&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Let’s say we have this project structure. Be aware that all our tests have the suffix “Tests” in the project name.&lt;/p&gt;

&lt;p&gt;The files are organized like this, so we have all “Tests” in a “tests” folder and the actual code under “src”:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;src/Sloader.Config
src/Sloader.Engine
src/Sloader.Hosts.Console
src/Sloader.Result
tests/Sloader.Config.Tests
tests/Sloader.Engine.Tests
tests/Sloader.Result.Tests
.gitignore
build.cake
build.ps1
LICENSE
Sloader.sln
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;goal&quot;&gt;Goal&lt;/h2&gt;

&lt;p&gt;Now we want to build all tests projects and run them with the xUnit console runner. Be aware that there are multiple ways of doing it, but I found this quite good.&lt;/p&gt;

&lt;h2 id=&quot;buildcake&quot;&gt;build.cake&lt;/h2&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;#tool &quot;nuget:?package=xunit.runner.console&quot;
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////

var target = Argument(&quot;target&quot;, &quot;Default&quot;);
var configuration = Argument(&quot;configuration&quot;, &quot;Release&quot;);

//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////

// Define directories.
var artifactsDir  = Directory(&quot;./artifacts/&quot;);
var rootAbsoluteDir = MakeAbsolute(Directory(&quot;./&quot;)).FullPath;

//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////

Task(&quot;Clean&quot;)
    .Does(() =&amp;gt;
{
    CleanDirectory(artifactsDir);
});

Task(&quot;Restore-NuGet-Packages&quot;)
    .IsDependentOn(&quot;Clean&quot;)
    .Does(() =&amp;gt;
{
    NuGetRestore(&quot;./Sloader.sln&quot;);
});

Task(&quot;Build&quot;)
    .IsDependentOn(&quot;Restore-NuGet-Packages&quot;)
    .Does(() =&amp;gt;
{

     
});

Task(&quot;BuildTests&quot;)
    .IsDependentOn(&quot;Restore-NuGet-Packages&quot;)
    .Does(() =&amp;gt;
{
	var parsedSolution = ParseSolution(&quot;./Sloader.sln&quot;);

	foreach(var project in parsedSolution.Projects)
	{
	
	if(project.Name.EndsWith(&quot;.Tests&quot;))
		{
        Information(&quot;Start Building Test: &quot; + project.Name);

        MSBuild(project.Path, new MSBuildSettings()
                .SetConfiguration(&quot;Debug&quot;)
                .SetMSBuildPlatform(MSBuildPlatform.Automatic)
                .SetVerbosity(Verbosity.Minimal)
                .WithProperty(&quot;SolutionDir&quot;, @&quot;.\&quot;)
                .WithProperty(&quot;OutDir&quot;, rootAbsoluteDir + @&quot;\artifacts\_tests\&quot; + project.Name + @&quot;\&quot;));
		}
	
	}    

});

Task(&quot;RunTests&quot;)
    .IsDependentOn(&quot;BuildTests&quot;)
    .Does(() =&amp;gt;
{
    Information(&quot;Start Running Tests&quot;);
    XUnit2(&quot;./artifacts/_tests/**/*.Tests.dll&quot;);
});

//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////

Task(&quot;Default&quot;)
    .IsDependentOn(&quot;RunTests&quot;);

//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////

RunTarget(target);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;explanation-buildtests&quot;&gt;Explanation: BuildTests?&lt;/h2&gt;

&lt;p&gt;The default target “Default” will trigger “RunTests”, which depend on “BuildTests”.&lt;/p&gt;

&lt;p&gt;Inside the “BuildTests”-target we use a handy helper from Cake and we parse the .sln file and search all “Test”-projects.
With that information we can build each test individually and don’t have to worry over “overlapping” files. 
The output of this build will be saved at &lt;strong&gt;“artifacts/_tests”&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;running-xunit&quot;&gt;Running xUnit&lt;/h2&gt;

&lt;p&gt;To run &lt;a href=&quot;http://cakebuild.net/dsl/xunit-v2/&quot;&gt;xUnit&lt;/a&gt; we have to include the runner at the top of the cake file:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;#tool &quot;nuget:?package=xunit.runner.console&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now we can just invoke XUnit2 and scan for all Tests.dlls and we are done:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;XUnit2(&quot;./artifacts/_tests/**/*.Tests.dll&quot;);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;result&quot;&gt;Result&lt;/h2&gt;

&lt;p&gt;The console output should make the flow pretty clear:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;PS C:\Users\Robert\Documents\GitHub\Sloader&amp;gt; .\build.ps1
Preparing to run build script...
Running build script...
Analyzing build script...
Processing build script...
Installing tools...
Compiling build script...

========================================
Clean
========================================
Executing task: Clean
Creating directory C:/Users/Robert/Documents/GitHub/Sloader/artifacts
Finished executing task: Clean

========================================
Restore-NuGet-Packages
========================================
Executing task: Restore-NuGet-Packages
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
All packages listed in packages.config are already installed.
Finished executing task: Restore-NuGet-Packages

========================================
BuildTests
========================================
Executing task: BuildTests
Start Building Test: Sloader.Config.Tests
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.

  Sloader.Config -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\artifacts\_tests\Sloader.Config.Tests\Sloader.Config.dll
  Sloader.Config.Tests -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\artifacts\_tests\Sloader.Config.Tests\Sloader.Config
  .Tests.dll
Start Building Test: Sloader.Result.Tests
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.

  Sloader.Result -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\artifacts\_tests\Sloader.Result.Tests\Sloader.Result.dll
  Sloader.Result.Tests -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\artifacts\_tests\Sloader.Result.Tests\Sloader.Result
  .Tests.dll
Start Building Test: Sloader.Engine.Tests
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.

  Sloader.Config -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\artifacts\_tests\Sloader.Engine.Tests\Sloader.Config.dll
  Sloader.Result -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\artifacts\_tests\Sloader.Engine.Tests\Sloader.Result.dll
  Sloader.Engine -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\artifacts\_tests\Sloader.Engine.Tests\Sloader.Engine.dll
  Sloader.Engine.Tests -&amp;gt; C:\Users\Robert\Documents\GitHub\Sloader\artifacts\_tests\Sloader.Engine.Tests\Sloader.Engine
  .Tests.dll
Finished executing task: BuildTests

========================================
RunTests
========================================
Executing task: RunTests
Start Running Tests
xUnit.net Console Runner (64-bit .NET 4.0.30319.42000)
  Discovering: Sloader.Config.Tests
  Discovered:  Sloader.Config.Tests
  Starting:    Sloader.Config.Tests
  Finished:    Sloader.Config.Tests
  Discovering: Sloader.Engine.Tests
  Discovered:  Sloader.Engine.Tests
  Starting:    Sloader.Engine.Tests
  Finished:    Sloader.Engine.Tests
  Discovering: Sloader.Result.Tests
  Discovered:  Sloader.Result.Tests
  Starting:    Sloader.Result.Tests
  Finished:    Sloader.Result.Tests
=== TEST EXECUTION SUMMARY ===
   Sloader.Config.Tests  Total: 22, Errors: 0, Failed: 0, Skipped: 0, Time: 0.342s
   Sloader.Engine.Tests  Total:  9, Errors: 0, Failed: 0, Skipped: 0, Time: 0.752s
   Sloader.Result.Tests  Total:  4, Errors: 0, Failed: 0, Skipped: 0, Time: 0.475s
                                --          -          -           -        ------
                   GRAND TOTAL: 35          0          0           0        1.569s (3.115s)
Finished executing task: RunTests

========================================
Default
========================================
Executing task: Default
Finished executing task: Default

Task                          Duration
--------------------------------------------------
Clean                         00:00:00.0155255
Restore-NuGet-Packages        00:00:00.5065704
BuildTests                    00:00:02.1590662
RunTests                      00:00:03.2443534
Default                       00:00:00.0061325
--------------------------------------------------
Total:                        00:00:05.9316480
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2017/02/07/build-and-run-xunit-tests-with-cake/</link>
                <guid>https://oliverguhr.github.io/Blog//2017/02/07/build-and-run-xunit-tests-with-cake</guid>
                <pubDate>Tue, 07 Feb 2017 23:45:00 +0000</pubDate>
        </item>

        <item>
                <title>GitHub API: Create or update files</title>
                <description>
&lt;p&gt;This blogpost covers a pretty basic GitHub topic: Creating and updating content on GitHub. Of course, there are many ways to do it - e.g. you could do the full Git-ceremony and it would work with all Git hosts, but in my case I just wanted to target the &lt;a href=&quot;https://developer.github.com/v3/&quot;&gt;&lt;strong&gt;offical GitHub API&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;prerequisite-a-github-user-repo-and-token&quot;&gt;Prerequisite: A GitHub User, Repo and Token&lt;/h2&gt;

&lt;p&gt;To use this code you will need write access to a GitHub repository and you should have a valid &lt;a href=&quot;https://github.com/settings/tokens&quot;&gt;GitHub token&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;code&quot;&gt;Code&lt;/h2&gt;

&lt;p&gt;The most simple way to communicate with the &lt;a href=&quot;https://developer.github.com/v3/&quot;&gt;GitHub API&lt;/a&gt; is by using the &lt;a href=&quot;https://www.nuget.org/packages/Octokit/&quot;&gt;Octokit SDK&lt;/a&gt; (from GitHub).&lt;/p&gt;

&lt;p&gt;Description:
Inside the try-block we try to &lt;a href=&quot;https://developer.github.com/v3/repos/contents/#get-contents&quot;&gt;get the target file&lt;/a&gt;, if it is already committed in the repo the API will return the last commit SHA.&lt;/p&gt;

&lt;p&gt;With this SHA it is possible to &lt;a href=&quot;https://developer.github.com/v3/repos/contents/#update-a-file&quot;&gt;create a new commit to do the actual update&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If the file was not found, &lt;a href=&quot;https://developer.github.com/v3/repos/contents/#create-a-file&quot;&gt;we create the file&lt;/a&gt;. I’m not a huge fan of this try/catch block, but didn’t found any other way to check if the file is comitted or not (please give me a hint if this is wrong ;))&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Octokit;

namespace CreateOrUpdateGitHubFile
{
    class Program
    {
        static void Main(string[] args)
        {
            Task.Run(async () =&amp;gt;
            {
                var ghClient = new GitHubClient(new ProductHeaderValue(&quot;Octokit-Test&quot;));
                ghClient.Credentials = new Credentials(&quot;ACCESS-TOKEN&quot;);

                // github variables
                var owner = &quot;OWNER&quot;;
                var repo = &quot;REPO&quot;;
                var branch = &quot;BRANCH&quot;;

                var targetFile = &quot;_data/test.txt&quot;;

                try
                {
                    // try to get the file (and with the file the last commit sha)
                    var existingFile = await ghClient.Repository.Content.GetAllContentsByRef(owner, repo, targetFile, branch);

                    // update the file
                    var updateChangeSet = await ghClient.Repository.Content.UpdateFile(owner, repo, targetFile,
                       new UpdateFileRequest(&quot;API File update&quot;, &quot;Hello Universe! &quot; + DateTime.UtcNow, existingFile.First().Sha, branch));
                }
                catch (Octokit.NotFoundException)
                {
                    // if file is not found, create it
                    var createChangeSet = await ghClient.Repository.Content.CreateFile(owner,repo, targetFile, new CreateFileRequest(&quot;API File creation&quot;, &quot;Hello Universe! &quot; + DateTime.UtcNow, branch));
                }

                
                
            }).Wait();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The demo code is also available on &lt;a href=&quot;https://github.com/Code-Inside/Samples/tree/master/2017/CreateOrUpdateGitHubFile&quot;&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Hope this helps.&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2017/01/02/create-or-update-files-via-the-github-api/</link>
                <guid>https://oliverguhr.github.io/Blog//2017/01/02/create-or-update-files-via-the-github-api</guid>
                <pubDate>Mon, 02 Jan 2017 23:45:00 +0000</pubDate>
        </item>

        <item>
                <title>DbProviderFactories: Write database agnostic ADO.NET code</title>
                <description>
&lt;p&gt;Recently I needed to write a module that needs to connect to a wide range of SQL-DBs, e.g. MySQL, MS SQL, Oracle etc.&lt;/p&gt;

&lt;h2 id=&quot;problem-most-providers-will-use-their-concret-classes&quot;&gt;Problem: Most providers will use their concret classes&lt;/h2&gt;

&lt;p&gt;If you look at the C# example on the &lt;a href=&quot;https://dev.mysql.com/doc/connector-net/en/connector-net-programming-connecting-open.html&quot;&gt;MySQL dev page&lt;/a&gt; you will see the MsSql-Namespace and classes:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;MySql.Data.MySqlClient.MySqlConnection conn;
string myConnectionString;

myConnectionString = &quot;server=127.0.0.1;uid=root;&quot; +
    &quot;pwd=12345;database=test;&quot;;

try
{
    conn = new MySql.Data.MySqlClient.MySqlConnection();
    conn.ConnectionString = myConnectionString;
    conn.Open();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
    MessageBox.Show(ex.Message);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The same classes will probably not work for a MS SQL database.&lt;/p&gt;

&lt;h2 id=&quot;solution-use-the-dbproviderfactories&quot;&gt;“Solution”: Use the DbProviderFactories&lt;/h2&gt;

&lt;p&gt;For example if you install the &lt;a href=&quot;https://www.nuget.org/packages/MySql.Data&quot;&gt;MySql-NuGet package&lt;/a&gt; you will also get this little enhancement to you app.config:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;system.data&amp;gt;
  &amp;lt;DbProviderFactories&amp;gt;
    &amp;lt;remove invariant=&quot;MySql.Data.MySqlClient&quot; /&amp;gt;
    &amp;lt;add name=&quot;MySQL Data Provider&quot; invariant=&quot;MySql.Data.MySqlClient&quot; description=&quot;.Net Framework Data Provider for MySQL&quot; type=&quot;MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d&quot; /&amp;gt;
  &amp;lt;/DbProviderFactories&amp;gt;
&amp;lt;/system.data&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now we can get a reference to the MySql client via the DbProviderFactories:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;using System;
using System.Data;
using System.Data.Common;

namespace DbProviderFactoryStuff
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine(&quot;All registered DbProviderFactories:&quot;);
                var allFactoryClasses = DbProviderFactories.GetFactoryClasses();

                foreach (DataRow row in allFactoryClasses.Rows)
                {
                    Console.WriteLine(row[0] + &quot;: &quot; + row[2]);
                }

                Console.WriteLine();
                Console.WriteLine(&quot;Try to access a MySql DB:&quot;);

                DbProviderFactory dbf = DbProviderFactories.GetFactory(&quot;MySql.Data.MySqlClient&quot;);
                using (DbConnection dbcn = dbf.CreateConnection())
                {
                    dbcn.ConnectionString = &quot;Server=localhost;Database=testdb;Uid=root;Pwd=Pass1word;&quot;;
                    dbcn.Open();
                    using (DbCommand dbcmd = dbcn.CreateCommand())
                    {
                        dbcmd.CommandType = CommandType.Text;
                        dbcmd.CommandText = &quot;SHOW TABLES;&quot;;

                        // parameter...
                        //var foo = dbcmd.CreateParameter();
                        //foo.ParameterName = &quot;...&quot;;
                        //foo.Value = &quot;...&quot;;

                        using (DbDataReader dbrdr = dbcmd.ExecuteReader())
                        {
                            while (dbrdr.Read())
                            {
                                Console.WriteLine(dbrdr[0]);
                            }
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }

            Console.ReadLine();

        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The most important line is this one:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;DbProviderFactory dbf = DbProviderFactories.GetFactory(&quot;MySql.Data.MySqlClient&quot;);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now with the &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/system.data.common.dbproviderfactory(v=vs.110).aspx&quot;&gt;&lt;strong&gt;DbProviderFactory&lt;/strong&gt;&lt;/a&gt; from the MySql client we can access the MySql database without using any MySql-specific classes.&lt;/p&gt;

&lt;p&gt;There are a couple of “in-built” db providers registered, like the MS SQL provider or ODBC stuff.&lt;/p&gt;

&lt;p&gt;The above code will output something like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;All registered DbProviderFactories:
Odbc Data Provider: System.Data.Odbc
OleDb Data Provider: System.Data.OleDb
OracleClient Data Provider: System.Data.OracleClient
SqlClient Data Provider: System.Data.SqlClient
Microsoft SQL Server Compact Data Provider 4.0: System.Data.SqlServerCe.4.0
MySQL Data Provider: MySql.Data.MySqlClient
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;other-solutions&quot;&gt;Other solutions&lt;/h2&gt;

&lt;p&gt;Of course there are other solutions - some OR-Mapper like the EntityFramework have a provider model which might also work, but this one here is a pretty basic approach.&lt;/p&gt;

&lt;h2 id=&quot;sql-commands&quot;&gt;SQL Commands&lt;/h2&gt;

&lt;p&gt;The tricky bit here is that you need to make sure that your SQL commands work on your database - this is &lt;strong&gt;not a silver bullet&lt;/strong&gt;, it &lt;strong&gt;just lets you connect and execute SQL commands to any ‘registered’ database&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The full demo code is also available on &lt;a href=&quot;https://github.com/Code-Inside/Samples/tree/master/2016/DbProviderFactoryStuff&quot;&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Hope this helps.&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2016/12/31/dbproviderfactory-write-database-agnostic-adonet-code/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/12/31/dbproviderfactory-write-database-agnostic-adonet-code</guid>
                <pubDate>Sat, 31 Dec 2016 14:00:00 +0000</pubDate>
        </item>

        <item>
                <title>Enable SSL with custom domains on GitHub Pages via Cloudflare</title>
                <description>
&lt;p&gt;Two weeks ago I decided (finally!) that I should enable SSL on this blog.&lt;/p&gt;

&lt;h2 id=&quot;problem-github-pages-with-a-custom-domain&quot;&gt;Problem: GitHub Pages with a custom domain&lt;/h2&gt;

&lt;p&gt;This blog is hosted on GitHub Pages with a custom domain, which currently doesn’t support SSL out of the box. If you stick with a github.io domain SSL is not a problem.&lt;/p&gt;

&lt;h2 id=&quot;cloudflare-to-the-rescure&quot;&gt;Cloudflare to the rescure&lt;/h2&gt;

&lt;p&gt;I decided to take a deeper look at &lt;strong&gt;&lt;a href=&quot;https://www.cloudflare.com&quot;&gt;Cloudflare&lt;/a&gt;&lt;/strong&gt;, which provides DNS, CDN and other “network”-related services. For the “main” service Cloudflare serves as the DNS for your domain and is like a proxy.&lt;/p&gt;

&lt;p&gt;With this setup you have some nice benefits:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A free SSL certificate (AFAIK you can also use your own cert if you need)&lt;/li&gt;
  &lt;li&gt;A CDN cache&lt;/li&gt;
  &lt;li&gt;DDOS protection&lt;/li&gt;
  &lt;li&gt;“Analytics”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Be aware: This is just the &lt;strong&gt;free plan&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And everything is pretty easy to manage via the web interface.&lt;/p&gt;

&lt;h3 id=&quot;setup&quot;&gt;Setup&lt;/h3&gt;

&lt;p&gt;The first step is to register at Cloudflare &amp;amp; setup your domain. After the first step you need to change the name server for your domain to Cloudflares server.&lt;/p&gt;

&lt;p&gt;All your domain belonging can now be managed inside Cloudflare:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-11-14/dns.png&quot; alt=&quot;x&quot; title=&quot;DNS&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;setting-up-some-rules&quot;&gt;Setting up some rules&lt;/h3&gt;

&lt;p&gt;When your DNS changes are done (which can take a couple of hours) you might want to introduce some basic rules. I use these settings, which enforces HTTPS and Cloudflare cache:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-11-14/rules.png&quot; alt=&quot;x&quot; title=&quot;Rules&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;done-or-nearly-done&quot;&gt;Done… or nearly done.&lt;/h3&gt;

&lt;p&gt;Now we have done the “Cloudflare-part”. The next step is to make sure that everything on your page uses HTTPS instead of HTTP to avoid “mixed content”-errors.&lt;/p&gt;

&lt;p&gt;Some notes from my own “migration”:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;If you have Google Analytics - make sure you change the property-settings to the HTTPS URL&lt;/li&gt;
  &lt;li&gt;If you use Disqus you &lt;strong&gt;need&lt;/strong&gt; to migrate your comments from the HTTP url to the HTTPS URL. There is a migrate tool available, which uses a CSV file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;other-solutions&quot;&gt;Other solutions…&lt;/h2&gt;

&lt;p&gt;As far as I know there are other, similar, providers out there and of course you can host the page yourself.&lt;/p&gt;

&lt;p&gt;Cloudflare is an easy solution if you are willing to hand of the DNS settings of your domain.&lt;/p&gt;

&lt;p&gt;Hope this helps!&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2016/11/14/ssl-with-custom-domains-on-gh-pages-via-cloudflare/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/11/14/ssl-with-custom-domains-on-gh-pages-via-cloudflare</guid>
                <pubDate>Mon, 14 Nov 2016 23:15:00 +0000</pubDate>
        </item>

        <item>
                <title>Writing loops in T-SQL</title>
                <description>
&lt;p&gt;The topic is quite old, but I found it really helpful, so be warned.&lt;/p&gt;

&lt;h2 id=&quot;scenario-iterate-over-a-result-set-and-insert-it-in-a-new-table-in-t-sql&quot;&gt;Scenario: Iterate over a result set and insert it in a new table in T-SQL&lt;/h2&gt;

&lt;p&gt;I had to write a SQL migration script to move date from an old table into a new table with a new primary key.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Update! I discovered that my problem would have been solved with a much simpler SQL script (INSERT INTO x …(SELECT … FROM Y)). So my example here is pretty dumb - sorry if this confuses you, but I will keep the blogpost to show the mechanics. Thanks Mark!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here was/is my resulting script using &lt;strong&gt;&lt;a href=&quot;https://msdn.microsoft.com/en-us/library/ms180169.aspx&quot;&gt;T-SQL Cursors&lt;/a&gt;&lt;/strong&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;DECLARE @TemplateId as uniqueidentifier;
DECLARE @UserId as uniqueidentifier;

DECLARE @OldTemplateFavCursor as CURSOR;

SET @OldTemplateFavCursor = CURSOR FOR
SELECT UserTemplate.[Template_Id], UserTemplate.[User_Id] FROM UserTemplate;
 
OPEN @OldTemplateFavCursor;
FETCH NEXT FROM @OldTemplateFavCursor INTO @TemplateId, @UserId;
 
WHILE @@FETCH_STATUS = 0
BEGIN
 INSERT INTO dbo.[UserFavoriteTemplate]
           ([Id]
           ,[TemplateId]
           ,[UserId])
     VALUES
           (NEWID()
           ,@TemplateId
           ,@UserId)

FETCH NEXT FROM @OldTemplateFavCursor INTO @TemplateId, @UserId;
END
 
CLOSE @OldTemplateFavCursor;
DEALLOCATE @OldTemplateFavCursor;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;explanation&quot;&gt;Explanation&lt;/h2&gt;

&lt;p&gt;In the first couple of lines we just declare some variables.&lt;/p&gt;

&lt;p&gt;In this particular script we want to move the “TemplateId” &amp;amp; “UserId” from the table “UserTemplate” into the target table “UserFavoriteTemplate”, but I also want to store an additional GUID as Id.&lt;/p&gt;

&lt;p&gt;This line will select our current data into the cursor:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SET @OldTemplateFavCursor = CURSOR FOR SELECT UserTemplate.[Template_Id], UserTemplate.[User_Id] FROM UserTemplate;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With the “OPEN”, “FETCH NEXT” and “CLOSE” we move the cursor and inside the “WHILE” we can do our migration.&lt;/p&gt;

&lt;p&gt;The syntax seems (from a C# perspective) strange, but works well for this scenario.&lt;/p&gt;

&lt;h2 id=&quot;performance-consideration&quot;&gt;Performance consideration&lt;/h2&gt;

&lt;p&gt;I wouldn’t recommend this approach for large scale migrations or actual production code because I heard that the performance is not as great as some clever joins or other T-SQL magic.&lt;/p&gt;

&lt;h2 id=&quot;make-sure-you-really-need-this&quot;&gt;Make sure you really need this&lt;/h2&gt;

&lt;p&gt;You can do some clever joins with SQL - make sure you really need this approach. My example here is not a clever one, so use this feature wisely. (again - thanks to Mark for the comment!)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks Christopher for your help!&lt;/strong&gt;&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2016/10/31/loops-in-tsql/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/10/31/loops-in-tsql</guid>
                <pubDate>Mon, 31 Oct 2016 22:15:00 +0000</pubDate>
        </item>

        <item>
                <title>Lets convert a WPF app to the Universal Windows Platform</title>
                <description>
&lt;h2 id=&quot;project-centennial---running-desktop-apps-in-the-uwp-world&quot;&gt;Project Centennial - running desktop apps in the UWP world&lt;/h2&gt;

&lt;p&gt;Last year Microsoft revealed the plans to run and distribute desktop apps (basically all apps ever written for Windows) in the Universal-Windows-Platform “universe”. The project titel was &lt;a href=&quot;https://www.microsoft.com/en-us/download/details.aspx?id=51691&quot;&gt;“Project Centennial”&lt;/a&gt; and a year later the tooling seems to be ok-ish. So, let’s try something simple and convert a simple WPF app to UWP.&lt;/p&gt;

&lt;h2 id=&quot;limitations-with-this-approach&quot;&gt;Limitations with this approach&lt;/h2&gt;

&lt;p&gt;Be aware that even if you can “convert” your WPF app this way you will get a UWP-ish app. The executable will only run &lt;strong&gt;on a normal Windows Desktop System&lt;/strong&gt;. The app will &lt;strong&gt;not work on a Windows Phone, Xbox or HoloLens&lt;/strong&gt; - at least not now.&lt;/p&gt;

&lt;p&gt;Also keep in mind that certain operations might fail and that the outcome of some operations might suprise you. The app itself will run in a kind of sandbox. Calls to the file system or registry will be faked. Details can be found &lt;a href=&quot;https://msdn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-behind-the-scenes&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As far as I know from a couple of hours playing around:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Changes to the Registry will not leak out of the sandbox, but for the app it will be seen as ok and is persistent&lt;/li&gt;
  &lt;li&gt;Changes to Well-Known-Folders (e.g. %AppData%) will not leak out of the sandbox, but for the app it will be seen as ok and is persistent&lt;/li&gt;
  &lt;li&gt;Some operation can leak out to the actual desktop, e.g. start another programm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;the-desktop-app-converter&quot;&gt;The Desktop App Converter&lt;/h2&gt;

&lt;p&gt;If you have an existing installer or setup you might want to take a look at the [desktop app converter](https://msdn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-run-desktop-app-converter. This utility will convert the installer to a UWP package.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://mtaulty.com/2016/09/29/a-quick-skip-through-the-desktop-app-converter/&quot;&gt;A quick walk through can be found on Mike Taultys blog&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;step-by-step---from-wpf-source-to-uwp-app&quot;&gt;Step by Step - from WPF source to UWP app&lt;/h2&gt;

&lt;p&gt;The important steps from the WPF app to a UWP app are also &lt;a href=&quot;https://msdn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-manual-conversion&quot;&gt;documented in the MSDN&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;But let’s start with a &lt;strong&gt;simple WPF app (running on .NET 4.6.1)&lt;/strong&gt; - this is the MainWindow.xaml&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;Window x:Class=&quot;WpfToUwpTestApp.MainWindow&quot;
        xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
        xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
        xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
        xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
        xmlns:local=&quot;clr-namespace:WpfToUwpTestApp&quot;
        mc:Ignorable=&quot;d&quot;
        Title=&quot;MainWindow - WpfToUwpTestApp&quot; Height=&quot;350&quot; Width=&quot;525&quot;&amp;gt;
    &amp;lt;StackPanel&amp;gt;
        &amp;lt;Button Height=&quot;100&quot; Width=&quot;100&quot; Click=&quot;Button_Click1&quot;&amp;gt;Write in Registry&amp;lt;/Button&amp;gt;
        &amp;lt;Button Height=&quot;100&quot; Width=&quot;100&quot; Click=&quot;Button_Click2&quot;&amp;gt;Write in AppData&amp;lt;/Button&amp;gt;
        &amp;lt;Button Height=&quot;100&quot; Width=&quot;100&quot; Click=&quot;Button_Click3&quot;&amp;gt;Open HTTP Address&amp;lt;/Button&amp;gt;

    &amp;lt;/StackPanel&amp;gt;
&amp;lt;/Window&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The code behind:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void Button_Click1(object sender, RoutedEventArgs e)
    {
        RegistryKey key = Registry.CurrentUser.OpenSubKey(&quot;Software&quot;, true);

        key.CreateSubKey(&quot;WpfToUwpTestApp&quot;);
        key = key.OpenSubKey(&quot;WpfToUwpTestApp&quot;, true);


        key.CreateSubKey(&quot;ItWorks&quot;);
        key = key.OpenSubKey(&quot;ItWorks&quot;, true);

        key.SetValue(&quot;ItWorks&quot;, &quot;true&quot;);
    }

    private void Button_Click2(object sender, RoutedEventArgs e)
    {
        string roaming = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

        string appFolder = System.IO.Path.Combine(roaming, &quot;WpfToUwpTestApp&quot;);

        string file = System.IO.Path.Combine(appFolder, &quot;Test.txt&quot;);

        if (Directory.Exists(appFolder) == false)
        {
            Directory.CreateDirectory(appFolder);
        }

        File.WriteAllText(file, &quot;Hello World!&quot;);
    }

    private void Button_Click3(object sender, RoutedEventArgs e)
    {
        Process.Start(&quot;http://www.google.com&quot;);
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Pretty simple, right? Those three operations came just to my mind. In general I wouldn’t use the Registry at all, but I had a use case in mind where I need to access the Registry.&lt;/p&gt;

&lt;p&gt;I also added a couple of dummy store images (from the default UWP app project template) - my solution looks like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-09-30/sln.png&quot; alt=&quot;x&quot; title=&quot;Solution&quot; /&gt;&lt;/p&gt;

&lt;p&gt;When we build the .csproj the output should look like this:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;WpfToUwpTestApp.exe&lt;/li&gt;
  &lt;li&gt;appxmanifest.xml&lt;/li&gt;
  &lt;li&gt;Assets/StoreLogo.png&lt;/li&gt;
  &lt;li&gt;Assets/Square150x150Logo.scale-200.png&lt;/li&gt;
  &lt;li&gt;Assets/Square44x44Logo.scale-200.png&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;the-appmanifestxml&quot;&gt;The appmanifest.xml&lt;/h2&gt;

&lt;p&gt;The next step is to create the &lt;strong&gt;appmanifest.xml&lt;/strong&gt; - on the &lt;a href=&quot;https://msdn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-manual-conversion&quot;&gt;MSDN there is a handy template&lt;/a&gt;. The Desktop App Converter does the same thing and tries to create this file automatically, but it’s not that hard to set it by hand:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;Package
   xmlns=&quot;http://schemas.microsoft.com/appx/manifest/foundation/windows10&quot;
   xmlns:uap=&quot;http://schemas.microsoft.com/appx/manifest/uap/windows10&quot;
   xmlns:rescap=&quot;http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities&quot;&amp;gt;
  &amp;lt;Identity Name=&quot;WpfToUwpTestApp&quot;
    ProcessorArchitecture=&quot;x64&quot;
    Publisher=&quot;CN=Robert&quot;
    Version=&quot;1.0.0.0&quot; /&amp;gt;
  &amp;lt;Properties&amp;gt;
    &amp;lt;DisplayName&amp;gt;WpfToUwpTestApp&amp;lt;/DisplayName&amp;gt;
    &amp;lt;PublisherDisplayName&amp;gt;Robert&amp;lt;/PublisherDisplayName&amp;gt;
    &amp;lt;Description&amp;gt;No description entered&amp;lt;/Description&amp;gt;
    &amp;lt;Logo&amp;gt;Assets/StoreLogo.png&amp;lt;/Logo&amp;gt;
  &amp;lt;/Properties&amp;gt;
  &amp;lt;Resources&amp;gt;
    &amp;lt;Resource Language=&quot;en-us&quot; /&amp;gt;
  &amp;lt;/Resources&amp;gt;
  &amp;lt;Dependencies&amp;gt;
    &amp;lt;TargetDeviceFamily Name=&quot;Windows.Desktop&quot; MinVersion=&quot;10.0.14316.0&quot; MaxVersionTested=&quot;10.0.14316.0&quot; /&amp;gt;
  &amp;lt;/Dependencies&amp;gt;
  &amp;lt;Capabilities&amp;gt;
    &amp;lt;rescap:Capability Name=&quot;runFullTrust&quot;/&amp;gt;
  &amp;lt;/Capabilities&amp;gt;
  &amp;lt;Applications&amp;gt;
    &amp;lt;Application Id=&quot;Test&quot; Executable=&quot;WpfToUwpTestApp.exe&quot; EntryPoint=&quot;Windows.FullTrustApplication&quot;&amp;gt;
      &amp;lt;uap:VisualElements
       BackgroundColor=&quot;#464646&quot;
       DisplayName=&quot;WpfToUwpTestApp&quot;
       Square150x150Logo=&quot;Assets/Square150x150Logo.scale-200.png&quot;
       Square44x44Logo=&quot;Assets/Square44x44Logo.scale-200.png&quot;
       Description=&quot;WpfUwpWriteInRegistry - Desc&quot; /&amp;gt;
    &amp;lt;/Application&amp;gt;
  &amp;lt;/Applications&amp;gt;
&amp;lt;/Package&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;create-the-appappx-package&quot;&gt;Create the App.appx package&lt;/h2&gt;

&lt;p&gt;Now we are ready to create the appx package. You need the Windows 10 SDK to do this.&lt;/p&gt;

&lt;p&gt;To simplify things, I copied the needed files from the build output to a folder called _App.&lt;/p&gt;

&lt;p&gt;To create the package, invoke the following command:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&quot;C:\Program Files (x86)\Windows Kits\10\bin\x64\makeappx.exe&quot; pack -d &quot;%~dp0_App&quot; -p &quot;%~dp0App.appx&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The result is a unsigned appx package called “App”.&lt;/p&gt;

&lt;h2 id=&quot;create-a-valid-pfx-one-time-only&quot;&gt;Create a valid pfx (one time only)&lt;/h2&gt;

&lt;p&gt;In the following step we need a valid pfx to sign the package. For development you can use this command to create a pfx:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&quot;C:\Program Files (x86)\Windows Kits\10\bin\x64\makecert.exe&quot; -r -h 0 -n &quot;CN=Robert&quot; -eku 1.3.6.1.5.5.7.3.3 -pe -sv App.pvk App.cer 

&quot;C:\Program Files (x86)\Windows Kits\10\bin\x64\pvk2pfx.exe&quot; -pvk App.pvk -spc App.cer -pfx App.pfx -po apptest
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After this you should see a “App.pfx” in the folder. I’m not 100% sure if this step is really needed, but I needed to do it, otherwise I couldn’t install the app:&lt;/p&gt;

&lt;p&gt;Now click on the pfx and enter the password “apptest” and import it in the “Trusted Root CAs”:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-09-30/trust.png&quot; alt=&quot;x&quot; title=&quot;Importing the pfx&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;sign-appappx&quot;&gt;Sign App.appx&lt;/h2&gt;

&lt;p&gt;Now we need to sign the package and we are done:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&quot;C:\Program Files (x86)\Windows Kits\10\bin\x64\signtool.exe&quot; sign /f &quot;App.pfx&quot; -fd SHA256 /p apptest &quot;App.appx&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;install-the-app&quot;&gt;Install the App!&lt;/h2&gt;

&lt;p&gt;Now you can double click on the appx package and the installer will show up:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-09-30/install.png&quot; alt=&quot;x&quot; title=&quot;install the app&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;running-the-app&quot;&gt;Running the App&lt;/h2&gt;

&lt;p&gt;And there is our beauty:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-09-30/app.png&quot; alt=&quot;x&quot; title=&quot;running the app&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;exploring-the-sandbox&quot;&gt;Exploring the sandbox:&lt;/h2&gt;

&lt;p&gt;Remember our 3 methods? The results of those three calls are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Write to the Registry: Seems to work for the app, but (as expected) the registry value will not leak out of the “sandbox”&lt;/li&gt;
  &lt;li&gt;Write to %appdata%: Seems to work for the app, but the data value will not leak out of the “sandbox”&lt;/li&gt;
  &lt;li&gt;Open a browser: The default browser will be invoked for a HTTP url.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It was my first try to convert a (simple) WPF app to UWP and the result is interesting.&lt;/p&gt;

&lt;p&gt;Hope my first steps in this world might help you!&lt;/p&gt;

&lt;p&gt;The code and a handy readme.txt is available on &lt;a href=&quot;https://github.com/Code-Inside/Samples/tree/master/2016/WpfToUwpTestApp&quot;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;from-the-comments-fun-with-registydat-files&quot;&gt;From the comments: Fun with registy.dat files:&lt;/h2&gt;

&lt;p&gt;James Hancock/John Galt discovered a nice registy trick. His goal was to “fake” a given registry key, so that the converted UWP app can see a “virtual” registry key. This can be done with a file named “registry.dat”.&lt;/p&gt;

&lt;p&gt;The registry.dat seems to be the source and target of all write actions inside the app:&lt;/p&gt;

&lt;p&gt;“The virtual registery is always the registry.dat. if you don’t provide a default version then one is created on first use for you.&lt;/p&gt;

&lt;p&gt;But if you do, then yes you can deploy whatever entries you want as a starting point for your app otherwise the starting point is whatever that computer currently has in the real registry.”&lt;/p&gt;

&lt;p&gt;You can create such registry.dat files via RegEdit &amp;amp; export it as registry hive. Be aware, that my test run wasn’t successful, but I hope to get working sample. Until that I hope James comments will be helpful.&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2016/09/30/lets-convert-a-wpf-app-to-uwp-via-the-uwp-bridge/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/09/30/lets-convert-a-wpf-app-to-uwp-via-the-uwp-bridge</guid>
                <pubDate>Fri, 30 Sep 2016 23:45:00 +0000</pubDate>
        </item>

        <item>
                <title>TFS 2015: Adding a new Windows Build Agent</title>
                <description>
&lt;h2 id=&quot;the-tfs-2015-build-system&quot;&gt;The TFS 2015 Build System&lt;/h2&gt;

&lt;p&gt;The build system before TFS 2015 was based on a pretty arcane XAML workflow engine which was manageable, but not fun to use. With TFS 2015 a new build system was implemented, which behave pretty much the same way as other build systems (e.g. TeamCity or AppVeyor).&lt;/p&gt;

&lt;p&gt;The “build workflow” is based on a simple “task”-concept.&lt;/p&gt;

&lt;p&gt;There are many related topics in the TFS world, e.g. Release-Management, but this blogpost will just focus on the “Getting the system ready”-part.&lt;/p&gt;

&lt;h2 id=&quot;tfs-build-agents&quot;&gt;TFS Build Agents&lt;/h2&gt;

&lt;p&gt;Like the other parts of Microsoft the TFS is now also in the cross-platform business. The build system in TFS 2015 is capable of building a huge range of languages. All you need is a 
compatible build agent.&lt;/p&gt;

&lt;p&gt;My (simple) goal was to build a .NET application on a Windows build agent via the new TFS 2015 build system.&lt;/p&gt;

&lt;h2 id=&quot;step-1-adding-a-new-build-agent&quot;&gt;Step 1: Adding a new build agent&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-08-10/adding-buildagent.png&quot; alt=&quot;Important - Download Agent&quot; title=&quot;Important - Download Agent&quot; /&gt;.&lt;/p&gt;

&lt;p&gt;This one is maybe the hardest part. Instead of a huge TFS-Agent-Installer.msi you need to navigate inside the TFS control panel to the &lt;strong&gt;“Agent pool”&lt;/strong&gt;-tab.&lt;/p&gt;

&lt;p&gt;You need at least one pool and need to click the “Download Agent” button.&lt;/p&gt;

&lt;h2 id=&quot;step-2-configure-the-agent&quot;&gt;Step 2: Configure the agent&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-08-10/config-buildagent.png&quot; alt=&quot;Configuration&quot; title=&quot;Configuration&quot; /&gt;.&lt;/p&gt;

&lt;p&gt;The .zip package contains the actual build agent executable and a .cmd file.&lt;/p&gt;

&lt;p&gt;Invoke the &lt;strong&gt;“ConfigureAgent.cmd”&lt;/strong&gt;-file:&lt;/p&gt;

&lt;p&gt;We run those agents as Windows Service (which was one of the last config-questions) and are pretty happy with the system.&lt;/p&gt;

&lt;h2 id=&quot;step-3-you-are-done&quot;&gt;Step 3: You are done&lt;/h2&gt;

&lt;p&gt;Now your new build agent should appear under the given build agent pool:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-08-10/resulting-buildagent.png&quot; alt=&quot;TFS Build Agents&quot; title=&quot;TFS Build Agents&quot; /&gt;.&lt;/p&gt;

&lt;h2 id=&quot;msdn-link&quot;&gt;MSDN Link&lt;/h2&gt;

&lt;p&gt;After googleing around I also found the &lt;strong&gt;&lt;a href=&quot;https://www.visualstudio.com/en-us/docs/build/agents/windows&quot;&gt;corresponding TFS HowTo&lt;/a&gt;&lt;/strong&gt;, which describes more or less the complete setup. Well… now it is documented on MSDN and this blog. Maybe this will help my future-self ;)&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2016/08/10/adding-a-new-windowsagent-to-tfs2015-build/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/08/10/adding-a-new-windowsagent-to-tfs2015-build</guid>
                <pubDate>Wed, 10 Aug 2016 23:45:00 +0000</pubDate>
        </item>

        <item>
                <title>CAKE: Building solutions with C# &amp; Roslyn</title>
                <description>
&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-07-09/cake.png&quot; alt=&quot;x&quot; title=&quot;CAKE - C# Make&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;cake---c-make&quot;&gt;CAKE - C# Make&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;A DSL for build tasks (e.g. build following projects, copy stuff, deploy stuff etc.)&lt;/li&gt;
  &lt;li&gt;It’s just C# code that gets compiled via Roslyn&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/cake-build/cake&quot;&gt;Active community, OSS &amp;amp; written in C#&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;You can get CAKE via &lt;a href=&quot;https://www.nuget.org/packages/Cake&quot;&gt;NuGet&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Before we begin you might want to check out the actual website of &lt;a href=&quot;http://cakebuild.net/&quot;&gt;CAKE&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Cross Platform support&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our goal: Building, running tests, package NuGet Packages etc.&lt;/p&gt;

&lt;h2 id=&quot;related-msbuild-and-fake-blogposts&quot;&gt;Related: MSBuild and FAKE blogposts&lt;/h2&gt;

&lt;p&gt;I already did a couple of MSBuild and FAKE related blogposts, so if you are interested on these topics as well go ahead (some are quite old, there is a high chance that some pieces might not apply anymore):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.codeinside.eu/2010/12/15/howto-msbuild-stylecop/&quot;&gt;MSBuild &amp;amp; Stylecop&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.codeinside.eu/2010/11/12/howto-build-msbuild-solutions/&quot;&gt;MSBuild &amp;amp; Building solutions&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.codeinside.eu/2010/11/21/howto-msdeploy-msbuild/&quot;&gt;MSBuild &amp;amp; MSDeploy&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.codeinside.eu/2010/11/24/howto-open-mstest-with-msbuild-2/&quot;&gt;MSBuild &amp;amp; MSTest 1&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.codeinside.eu/2010/11/29/howto-open-mstest-with-msbuild/&quot;&gt;MSBuild &amp;amp; MSTest 2&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.codeinside.eu/2011/01/06/howto-msbuild-nuit/&quot;&gt;MSBuild &amp;amp; NUnit&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;http://blog.codeinside.eu/2010/12/06/howto-web-config-transformations-with-msbuild/&quot;&gt;MSBuild &amp;amp; Web.config Transformations&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.codeinside.eu/2015/02/23/fake-building-with-fake/&quot;&gt;“FAKE: Building C# projects without knowing a tiny bit of F#”&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.codeinside.eu/2015/02/24/fake-running-xunit-tests-with-fake/&quot;&gt;“FAKE: Running xUnit Tests with FAKE without knowing a tiny bit of F#”&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.codeinside.eu/2015/06/21/fake-create-nuget-packages/&quot;&gt;“FAKE: Create NuGet Packages without knowing a tiny bit of F#”&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.codeinside.eu/2015/08/30/fake-running-mstest-tests-with-fake/&quot;&gt;“FAKE: Running MSTest Tests with FAKE without knowing a tiny bit of F#”&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.codeinside.eu/2016/06/12/fake-build-aspnet-projects-with-webconfig-transform/&quot;&gt;“FAKE: Build ASP.NET projects with web.config transformation (and without knowing a tiny bit of F#)”&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ok… now back to CAKE.&lt;/p&gt;

&lt;h2 id=&quot;lets-start-with-the-basics-building&quot;&gt;Let’s start with the basics: Building&lt;/h2&gt;

&lt;p&gt;I created a pretty simple WPF app and &lt;a href=&quot;http://cakebuild.net/docs/tutorials/setting-up-a-new-project&quot;&gt;followed these instructions&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;the-buildcake-script&quot;&gt;The build.cake script&lt;/h2&gt;

&lt;p&gt;My script is a simplified version &lt;a href=&quot;https://github.com/cake-build/example/blob/master/build.cake&quot;&gt;of this build script&lt;/a&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// ARGUMENTS
var target = Argument(&quot;target&quot;, &quot;Default&quot;);

// TASKS
Task(&quot;Restore-NuGet-Packages&quot;)
    .Does(() =&amp;gt;
{
    NuGetRestore(&quot;CakeExampleWithWpf.sln&quot;);
});

Task(&quot;Build&quot;)
    .IsDependentOn(&quot;Restore-NuGet-Packages&quot;)
    .Does(() =&amp;gt;
{
      MSBuild(&quot;CakeExampleWithWpf.sln&quot;, settings =&amp;gt;
        settings.SetConfiguration(&quot;Release&quot;));

});

// TASK TARGETS
Task(&quot;Default&quot;).IsDependentOn(&quot;Build&quot;);

// EXECUTION
RunTarget(target);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If you know FAKE or MSBuild, this is more or less the same structure. You define tasks, which may depend on other tasks. At the end you invoke one task and the dependency chain will do its work.&lt;/p&gt;

&lt;h2 id=&quot;invoke-buildcake&quot;&gt;Invoke build.cake&lt;/h2&gt;

&lt;p&gt;The “build.ps1” will invoke “tools/cake.exe” with the input file “build.cake”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;“build.ps1” is just a helper.&lt;/strong&gt; 
This Powershell script will download nuget.exe and download the CAKE NuGet-Package and extract it under a /tools folder. If you don’t have problems with binary files in your source control, you don’t need this Powershell script.&lt;/p&gt;

&lt;h2 id=&quot;our-first-cake-script&quot;&gt;Our first CAKE script!&lt;/h2&gt;

&lt;p&gt;The output is very well formatted and should explain the mechanics behind it good enough:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Time Elapsed 00:00:02.86
Finished executing task: Build

========================================
Default
========================================
Executing task: Default
Finished executing task: Default

Task                          Duration
--------------------------------------------------
Restore-NuGet-Packages        00:00:00.5192250
Build                         00:00:03.1315658
Default                       00:00:00.0113019
--------------------------------------------------
Total:                        00:00:03.6620927
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The first steps are pretty easy and it’s much easier than MSBuild and feels good if you know C#.&lt;/p&gt;

&lt;p&gt;The super simple intro code can be found on &lt;a href=&quot;https://github.com/Code-Inside/Samples/tree/master/2016/CakeIntro&quot;&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2016/07/09/cake-building-with-cake/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/07/09/cake-building-with-cake</guid>
                <pubDate>Sat, 09 Jul 2016 14:15:00 +0000</pubDate>
        </item>

        <item>
                <title>FAKE: Build ASP.NET projects with web.config transformation (and without knowing a tiny bit of F#)</title>
                <description>
&lt;p&gt;&lt;em&gt;This is a follow-up to my other FAKE posts:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.codeinside.eu/2015/02/23/fake-building-with-fake/&quot;&gt;“FAKE: Building C# projects without knowing a tiny bit of F#”&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.codeinside.eu/2015/02/24/fake-running-xunit-tests-with-fake/&quot;&gt;“FAKE: Running xUnit Tests with FAKE without knowing a tiny bit of F#”&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.codeinside.eu/2015/06/21/fake-create-nuget-packages/&quot;&gt;“FAKE: Create NuGet Packages without knowing a tiny bit of F#”&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.codeinside.eu/2015/08/30/fake-running-mstest-tests-with-fake/&quot;&gt;“FAKE: Running MSTest Tests with FAKE without knowing a tiny bit of F#”&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;whats-the-difference-between-a-aspnet-and-other-projects&quot;&gt;What’s the difference between a ASP.NET and other projects?&lt;/h2&gt;

&lt;p&gt;The most obvious difference is that the output is a bunch of dlls and content files. Additionally you might have a &lt;strong&gt;web.debug.config or web.release.config&lt;/strong&gt; in your source folder.&lt;/p&gt;

&lt;p&gt;Both files are important, because they are used during a Visual-Studio build as a &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/dd465326(v=vs.110).aspx&quot;&gt;&lt;strong&gt;Web.Config Transformation&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;With a normal build the transformation will not kick in, so we need a way to trigger the transformation “manually”.&lt;/p&gt;

&lt;h2 id=&quot;project-overview&quot;&gt;Project Overview&lt;/h2&gt;

&lt;p&gt;The sample project consists of one ASP.NET project and the .fsx file.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-06-12/project.png&quot; alt=&quot;x&quot; title=&quot;Project Overview&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The “released” web.config should cover this 3 main transformation parts:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;DefaultConnectionString to ‘ReleaseSQLServer’&lt;/li&gt;
  &lt;li&gt;No “debug”-attribute on system.web&lt;/li&gt;
  &lt;li&gt;developmentMode-AppSetting set to ‘true’&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Web.Release.config&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;?xml version=&quot;1.0&quot;?&amp;gt;
&amp;lt;configuration xmlns:xdt=&quot;http://schemas.microsoft.com/XML-Document-Transform&quot;&amp;gt;
  &amp;lt;connectionStrings&amp;gt;
    &amp;lt;add name=&quot;DefaultConnection&quot;
      connectionString=&quot;ReleaseSQLServer&quot;
      xdt:Transform=&quot;SetAttributes&quot; xdt:Locator=&quot;Match(name)&quot;/&amp;gt;
  &amp;lt;/connectionStrings&amp;gt;

  &amp;lt;appSettings&amp;gt;
    &amp;lt;add key=&quot;developmentMode&quot; value=&quot;true&quot; xdt:Transform=&quot;SetAttributes&quot;
         xdt:Locator=&quot;Match(key)&quot;/&amp;gt;
  &amp;lt;/appSettings&amp;gt;
  
  &amp;lt;system.web&amp;gt;
    &amp;lt;compilation xdt:Transform=&quot;RemoveAttributes(debug)&quot; /&amp;gt;
  &amp;lt;/system.web&amp;gt;
&amp;lt;/configuration&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;the-fake-script&quot;&gt;The FAKE script&lt;/h2&gt;

&lt;p&gt;We reuse the MSBuild-Helper from FAKE and inject a couple of “Publish”-related stuff, which will trigger the transformation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A few remarks:&lt;/strong&gt; In the “normal” WebDeploy-World you would have a PublishProfile and it would end up with a .zip-file and a couple of other files that fill in parameters like the ConnectionString. With this MSBuild command I mimik a part of this behavior and use the temporary output as our main artifact. In my most apps I use web.config transformations only for “easy” stuff (e.g. remove the debug attribute) - if you are doing fancy stuff and the output is not what you want, please let me know.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This MSBuild command &lt;em&gt;should&lt;/em&gt; apply all your web.config transformations.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Publish a ASP.NET project&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;...
Target &quot;BuildWebApp&quot; (fun _ -&amp;gt;
trace &quot;Building WebHosted Connect...&quot;
!! &quot;**/*.csproj&quot;
 |&amp;gt; MSBuild artifactsBuildDir &quot;Package&quot;
    [&quot;Configuration&quot;, &quot;Release&quot;
     &quot;Platform&quot;, &quot;AnyCPU&quot;
     &quot;AutoParameterizationWebConfigConnectionStrings&quot;, &quot;False&quot;
     &quot;_PackageTempDir&quot;, (@&quot;..\&quot; + artifactsDir + @&quot;Release-Ready-WebApp&quot;)
     ]
 |&amp;gt; Log &quot;AppBuild-Output: &quot;
)
...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;autoparameterizationwebconfigconnectionstrings-or-how-to-get-rid-of-replacabletoken_&quot;&gt;“AutoParameterizationWebConfigConnectionStrings” or how to get rid of $(ReplacableToken_…&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Blogpost updated on 2016-07-18&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A friend told me that his transformed web.config contained “$(ReplaceableToken_…)” strings. It seems that “connectionStrings” are treated specially. If you have a connectionString in your web.config and don’t set &lt;a href=&quot;http://stackoverflow.com/questions/7207689/how-to-get-rid-of-replacabletoken-in-web-config-completely&quot;&gt;“AutoParameterizationWebConfigConnectionStrings=False”&lt;/a&gt; you will get something like that:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;connectionStrings&amp;gt;
  &amp;lt;!-- Not the result we are looking for :-/ --&amp;gt;
  &amp;lt;add name=&quot;DefaultConnection&quot; connectionString=&quot;$(ReplacableToken_DefaultConnection-Web.config Connection String_0)&quot; providerName=&quot;System.Data.SqlClient&quot; /&amp;gt;
&amp;lt;/connectionStrings&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I would say this is not the result you are expecting. With the “AutoParameterizationWebConfigConnectionStrings=False” parameter it should either do a transformation or leave the default-connectionString value in the result.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks to Timur Zanagar! I completely missed this issue.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;result&quot;&gt;Result&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-06-12/output.png&quot; alt=&quot;x&quot; title=&quot;Output&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This build will produce two artifacts - the build-folder just contains the normal build output, but &lt;strong&gt;without&lt;/strong&gt; a web.config transformation.&lt;/p&gt;

&lt;p&gt;The other folder contains a ready to deploy web application, &lt;strong&gt;with the web.release.config applied&lt;/strong&gt;.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;connectionStrings&amp;gt;
  &amp;lt;add name=&quot;DefaultConnection&quot; connectionString=&quot;ReleaseSQLServer&quot; providerName=&quot;System.Data.SqlClient&quot; /&amp;gt;
&amp;lt;/connectionStrings&amp;gt;
&amp;lt;appSettings&amp;gt;
  ...
  &amp;lt;add key=&quot;developmentMode&quot; value=&quot;true&quot; /&amp;gt;
&amp;lt;/appSettings&amp;gt;
&amp;lt;system.web&amp;gt;
  ...
&amp;lt;/system.web&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can find the complete &lt;a href=&quot;https://github.com/Code-Inside/Samples/tree/master/2016/LetsUseFake-AspNet&quot;&gt;sample &amp;amp; build script on GitHub&lt;/a&gt;.&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2016/06/12/fake-build-aspnet-projects-with-webconfig-transform/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/06/12/fake-build-aspnet-projects-with-webconfig-transform</guid>
                <pubDate>Sun, 12 Jun 2016 14:00:00 +0000</pubDate>
        </item>

        <item>
                <title>Copy to clipboard with Javascript</title>
                <description>
&lt;h2 id=&quot;clipboard-current-state-of-the-art&quot;&gt;Clipboard? Current state of the art…&lt;/h2&gt;

&lt;p&gt;I think everybody knows the clipboard. The goal is that we can store text inside the users clipboard, so he can just paste it. Most sites uses either Flash or some sort of mini-popup with a pre-selected text inside a textarea.&lt;/p&gt;

&lt;p&gt;Both ways are not super user friendly and Flash is definitely done.&lt;/p&gt;

&lt;h2 id=&quot;clipboard-api&quot;&gt;Clipboard API?&lt;/h2&gt;

&lt;p&gt;Currently there are some draft specs for a real clipboard API, but as far as I know, it’s far from &lt;a href=&quot;http://caniuse.com/#feat=clipboard&quot;&gt;done&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The good news:&lt;/strong&gt; For our use case there is a pretty handy workaround available, which I found on &lt;a href=&quot;http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript&quot;&gt;StackOverflow&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;the-code&quot;&gt;The code:&lt;/h2&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;script&amp;gt;
    function detectIE() {
        var ua = window.navigator.userAgent;

        var msie = ua.indexOf('MSIE ');
        if (msie &amp;gt; 0) {
            // IE 10 or older =&amp;gt; return version number
            return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
        }

        var trident = ua.indexOf('Trident/');
        if (trident &amp;gt; 0) {
            // IE 11 =&amp;gt; return version number
            var rv = ua.indexOf('rv:');
            return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
        }

        // other browser or edge
        return false;
    }

    // source: http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript
    // enhancement with special case for IEs, otherwise the temp textarea will be visible
    function copyTextToClipboard(text) {
        if (detectIE()) {
            try {
                window.clipboardData.setData('Text', text);
                console.log('Copying text command via IE-setData');
            } catch (err) {
                console.log('Oops, unable to copy via IE-setData');
            }
        }
        else {

            var textArea = document.createElement(&quot;textarea&quot;);

            //
            //  This styling is an extra step which is likely not required. 
            //
            // Why is it here? To ensure:
            // 1. the element is able to have focus and selection.
            // 2. if element was to flash render it has minimal visual impact.
            // 3. less flakyness with selection and copying which might occur if
            //    the textarea element is not visible.
            //
            // The likelihood is the element won't even render, not even a flash,
            // so some of these are just precautions. 
            // 
            // However in IE the element
            // is visible whilst the popup box asking the user for permission for
            // the web page to copy to the clipboard. To prevent this, we are using 
            // the detectIE workaround.

            // Place in top-left corner of screen regardless of scroll position.
            textArea.style.position = 'fixed';
            textArea.style.top = 0;
            textArea.style.left = 0;

            // Ensure it has a small width and height. Setting to 1px / 1em
            // doesn't work as this gives a negative w/h on some browsers.
            textArea.style.width = '2em';
            textArea.style.height = '2em';

            // We don't need padding, reducing the size if it does flash render.
            textArea.style.padding = 0;

            // Clean up any borders.
            textArea.style.border = 'none';
            textArea.style.outline = 'none';
            textArea.style.boxShadow = 'none';

            // Avoid flash of white box if rendered for any reason.
            textArea.style.background = 'transparent';


            textArea.value = text;

            document.body.appendChild(textArea);

            textArea.select();

            try {
                var successful = document.execCommand('copy');
                var msg = successful ? 'successful' : 'unsuccessful';
                console.log('Copying text command was ' + msg);
            } catch (err) {
                console.log('Oops, unable to copy');
            }

            document.body.removeChild(textArea);
        }

    }
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;usage&quot;&gt;Usage:&lt;/h2&gt;

&lt;p&gt;The usage is pretty simple, just call copyToClipboard, e.g.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;button type=&quot;button&quot; onclick=&quot;copyTextToClipboard('Foobar!')&quot;&amp;gt;
	Set Foobar to clipboard
&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;documentexeccommandcopy&quot;&gt;document.execCommand(‘copy’)&lt;/h2&gt;

&lt;p&gt;This API is a bit strange, because it only works for visible elements and IE might render a small warning. To get rid of this effect we use a older IE-only API. “document.execCommand” is not limited to copy - there are some nice ideas around it. The &lt;strong&gt;&lt;a href=&quot;https://developer.mozilla.org/de/docs/Web/API/Document/execCommand&quot;&gt;Mozilla site&lt;/a&gt;&lt;/strong&gt; has a large documentation about this function.&lt;/p&gt;

&lt;p&gt;A full demo is available on &lt;strong&gt;&lt;a href=&quot;https://jsfiddle.net/uxozxb04/1/&quot;&gt;JSFiddle&lt;/a&gt;&lt;/strong&gt; and the code is stored on &lt;a href=&quot;https://github.com/Code-Inside/Samples/tree/master/2016/clipboardjs&quot;&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope this helps.&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2016/05/12/copy-to-clipboard-with-javascript/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/05/12/copy-to-clipboard-with-javascript</guid>
                <pubDate>Thu, 12 May 2016 23:55:00 +0000</pubDate>
        </item>

        <item>
                <title>Get the Windows 10 or 8 accent color in WPF</title>
                <description>
&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-04-26/windows-accent.png&quot; alt=&quot;x&quot; title=&quot;Windows Color Options&quot; /&gt;.&lt;/p&gt;

&lt;h2 id=&quot;windows-accent-color&quot;&gt;Windows Accent Color&lt;/h2&gt;

&lt;p&gt;Since Windows 8 users can choose a system accent color. The color can be seen on the window borders of the default apps and it can be pretty easy be used inside a &lt;a href=&quot;http://firstfloorsoftware.com/news/win10-dev-using-systemaccentcolor&quot;&gt;UWP App&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;how-to-get-the-accent-color-in-wpf&quot;&gt;How to get the accent color in WPF?&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Option 1: SystemParameters.WindowGlassBrush - not 100% the same color&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As far as I know there are several ways to get the color code, one easy but &lt;strong&gt;not 100% correct&lt;/strong&gt; way is to use the &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/system.windows.systemparameters.windowglassbrush.aspx&quot;&gt;SystemParameters.WindowGlassBrush&lt;/a&gt; property that was introduced in .NET 4.5.&lt;/p&gt;

&lt;p&gt;Sadly, the color is not 100% correct - I have no idea where this “similar”, but not identical color is used and why the API is returning this color.&lt;/p&gt;

&lt;p&gt;It seems this is just a wrapper around the &lt;strong&gt;undocumented&lt;/strong&gt; DwmGetColorizationParameters Win32 API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option 2: GetImmersiveColorFromColorSetEx&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I found this solution &lt;a href=&quot;https://gist.github.com/paulcbetts/3c6aedc9f0cd39a77c37&quot;&gt;here&lt;/a&gt;, which is just a wrapper around the &lt;strong&gt;GetImmersiveColorFromColorSetEx&lt;/strong&gt; Win32 API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option 3: Registry, DwmGetColorizationParameters&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The last option would be to read the Registry values - I found some hints on this &lt;a href=&quot;http://pinvoke.net/default.aspx/dwmapi/DwmGetColorizationParameters.html&quot;&gt;site&lt;/a&gt;, but I wouldn’t recommend it, because it is more or less undocumented and might break in the future. So we will use option 1 or 2.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Usage:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The usage of both options is pretty easy (at least with the option 2 code provided) :&lt;/p&gt;

&lt;div class=&quot;language-cs highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;c1&quot;&gt;// https://gist.github.com/paulcbetts/3c6aedc9f0cd39a77c37&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;accentColor&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;SolidColorBrush&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AccentColorSet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ActiveSet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;SystemAccent&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Code&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Background&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;accentColor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Code&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Text&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;AccentColorSet Immersive 'SystemAccent' &quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;accentColor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ToString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// Available in .NET 4.5&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SystemProperties&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Background&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SystemParameters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WindowGlassBrush&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SystemProperties&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Text&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;SystemParameters.WindowGlassBrush &quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SolidColorBrush&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SystemParameters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WindowGlassBrush&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ToString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-04-26/wpf-result.png&quot; alt=&quot;x&quot; title=&quot;WPF result&quot; /&gt;.&lt;/p&gt;

&lt;p&gt;&lt;del&gt;As you can see, the lower color does match the border color instead of the first option. Crazy, right?&lt;/del&gt; ¯\_(ツ)_/¯&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;From the comments:&lt;/strong&gt; As Yves Goergen pointed out, the resulting color &lt;strong&gt;does not&lt;/strong&gt; exactly match the &lt;strong&gt;border color&lt;/strong&gt;, but it &lt;strong&gt;does match the system accent color&lt;/strong&gt;, which is ok. I would guess that the border has some chrome behavior attached so that the color is slightly different.&lt;/p&gt;

&lt;p&gt;The full code is on &lt;a href=&quot;https://github.com/Code-Inside/Samples/tree/master/2016/WpfGetWindows10AccentColor&quot;&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope this helps.&lt;/p&gt;

</description>
                <link>https://oliverguhr.github.io/Blog//2016/04/26/get-the-windows-10-or-8-accent-color-from-wpf/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/04/26/get-the-windows-10-or-8-accent-color-from-wpf</guid>
                <pubDate>Tue, 26 Apr 2016 23:55:00 +0000</pubDate>
        </item>

        <item>
                <title>Debugging .NET based Windows Error Reports (WER)</title>
                <description>
&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-03-23/crash.gif&quot; alt=&quot;x&quot; title=&quot;Windows App Crash&quot; /&gt;.&lt;/p&gt;

&lt;h2 id=&quot;the-last-hope-windows-error-reports&quot;&gt;The last hope: Windows Error Reports&lt;/h2&gt;

&lt;p&gt;The “Windows Error Report” (WER) is automatically generated by Windows and can be seen in the Eventlog. In most cases, you might see some other - debugging friendlier - event logs. If there is a event log from with the source “.NET Runtime”, then use this first. Windows Error Reports are at first a bit strange to read.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-03-23/eventlog-wer.png&quot; alt=&quot;x&quot; title=&quot;Windows Error Report&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Small, but important hint:&lt;/strong&gt;
I strongly recommend that you should use some logging libraries inside your application as well.&lt;/p&gt;

&lt;p&gt;If you still don’t have a clue where your application breaks or those other event logs are missing the WER can be used to see where the exception is thrown in your .NET application.&lt;/p&gt;

&lt;h2 id=&quot;windows-error-report-for-net-apps&quot;&gt;Windows Error Report for .NET Apps&lt;/h2&gt;

&lt;p&gt;A typical Windows Error Report could look like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Fault bucket 129047406839, type 5
Event Name: CLR20r3
Response: Not available
Cab Id: 0

Problem signature:
P1: BreakStuff.App.exe
P2: 1.0.0.0
P3: 56eb2416
P4: BreakStuff.App
P5: 1.0.0.0
P6: 56eb2416
P7: 5
P8: a
P9: FatalError
P10: 

Attached files:
C:\Users\Robert\AppData\Local\Temp\WERE708.tmp.WERInternalMetadata.xml
C:\Users\Robert\AppData\Local\Temp\WERF4B5.tmp.appcompat.txt
C:\ProgramData\Microsoft\Windows\WER\Temp\WERF4D5.tmp.dmp
C:\Users\Robert\AppData\Local\Temp\WERF65D.tmp.WERDataCollectionFailure.txt
C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_BreakStuff.App.e_1952fbbdf8ecceaa6e9af5c44339210849f4774_b2bbc455_cab_7634f669\memory.hdmp
WERGenerationLog.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Each &lt;a href=&quot;https://blogs.msdn.microsoft.com/oanapl/2009/01/30/windows-error-reporting-and-clr-integration/&quot;&gt;P holds some exception location information&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;P1: “BreakStuff.App.exe” = App name or host process&lt;/strong&gt; e.g. your.exe or Outlook.exe for a .NET addin.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;P2: “1.0.0.0” = Version of the executabe&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;P3: “56eb2416” = Timestamp of the executable&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;P4: “BreakStuff.App” = Faulting assembly and module name&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;P5: “1.0.0.0”&lt;/strong&gt; = Version of the faulting module&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;P6: “56eb2416” = Timestamp of the faulting module&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;P7: “5” = MethodDef&lt;/strong&gt; – MethodDef token for the faulting method, after stripping off the high byte. This is the faulting method in your code. &lt;em&gt;Super important!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;P8: “a” = IL offset&lt;/strong&gt; - in hex, in combination with P7 will it show you the &lt;em&gt;exact position of the exception&lt;/em&gt; in your method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;P9: “FatalError”&lt;/strong&gt; = Exception type&lt;/p&gt;

&lt;p&gt;P1-P3 should be easy to understand and nothing new to you. If you have a bigger application P4 might lead to the correct namespace/assembly.&lt;/p&gt;

&lt;p&gt;Most important to find the real source is P7 &amp;amp; P8 - I will show you how to read it.&lt;/p&gt;

&lt;h2 id=&quot;p7-finding-the-methoddef-token-with-ildasmexe&quot;&gt;P7: Finding the MethodDef token with ILDASM.exe&lt;/h2&gt;

&lt;p&gt;P7 tells you in which method the exception occurred. The number shown in P7 is the method token, which is the IL representation of your actual method in code. To see the real method name we need a tool.&lt;/p&gt;

&lt;p&gt;As far as I know you could try to use WinDbg, but I was too stupid to use it correctly - ildasm.exe does also work for our use case. To get the method token you need “ildasm.exe”, which is included in the .NET SDK, which is part of the Windows SDK.&lt;/p&gt;

&lt;p&gt;On a Windows 10 machine, with &lt;a href=&quot;https://dev.windows.com/en-us/downloads/windows-10-sdk&quot;&gt;the SDK&lt;/a&gt; installed, you can use this version:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools\ildasm.exe
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For ILDASM it is not important if the actual .NET app is using .NET 4.6 or any other version.&lt;/p&gt;

&lt;p&gt;“ildasm.exe” itself is not a beauty, but works. Now open your assembly from &lt;strong&gt;P4&lt;/strong&gt; with this tool.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-03-23/ildsam.png&quot; alt=&quot;x&quot; title=&quot;using ildsam to get the method token&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To see the tokens, press &lt;strong&gt;CTRL + M&lt;/strong&gt; and search for &lt;strong&gt;P7&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In my case I see this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Method #2 (06000005) 
-------------------------------------------------------
	MethodName: ButtonBase_OnClick (06000005)
	Flags     : [Private] [HideBySig] [ReuseSlot]  (00000081)
	RVA       : 0x0000208c
	ImplFlags : [IL] [Managed]  (00000000)
	CallCnvntn: [DEFAULT]
	hasThis 
	ReturnType: Void
	2 Arguments
		Argument #1:  Object
		Argument #2:  Class System.Windows.RoutedEventArgs
	2 Parameters
		(1) ParamToken : (08000001) Name : sender flags: [none] (00000000)
		(2) ParamToken : (08000002) Name : e flags: [none] (00000000)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Take a look at the method description: 0600000 &lt;strong&gt;5&lt;/strong&gt; - the 0600000 is the high byte (whatever that means… - just search for the number, I bet you will find something.)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;BigBasti helped me in the comments to describe the high byte:
Big numbers which need more than one byte to store the value have high bytes (most significant bytes) and low bytes (least significant bytes) - you need to know this to make sure you load the sequence of bytes in the correct order. - Thanks!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Ok - now we know the actual method. The exception occurs in the ButtonBase_OnClick method!&lt;/p&gt;

&lt;h2 id=&quot;p8-finding-the-exact-position-of-the-faulting-code-with-ilspy&quot;&gt;P8: Finding the exact position of the faulting code with ILSpy&lt;/h2&gt;

&lt;p&gt;Now we need to look at the methods IL. You can use &lt;a href=&quot;http://ilspy.net/&quot;&gt;ILSpy&lt;/a&gt; or any other .NET decompiler (ildasm is not very comfortable, we only used it to get the method name). 
If you choosed ILSpy make sure you switch from the C# view to IL view and go to the faulting method:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-03-23/ilspy-code.png&quot; alt=&quot;x&quot; title=&quot;ILSpy&quot; /&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// Method begins at RVA 0x208c
// Code size 11 (0xb)
.maxstack 8

IL_0000: ldstr &quot;I'm dead!&quot;
IL_0005: call void [mscorlib]System.Environment::FailFast(string)
IL_000a: ret
} // end of method MainWindow::ButtonBase_OnClick
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As you might remember - P8 pointed to “a”, which is the IL_000a instruction.&lt;/p&gt;

&lt;p&gt;Mission accomplished: Exception source found! Yay!&lt;/p&gt;

&lt;h2 id=&quot;big-picture&quot;&gt;Big picture&lt;/h2&gt;

&lt;p&gt;I never thought I had to read the internal IL, but we had one weird case where no log files were generated and we used this trick to get to the source of the exception.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-03-23/bigpicture.png&quot; alt=&quot;x&quot; title=&quot;Big Picture of WER debugging&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://github.com/Code-Inside/Samples/tree/master/2016/BreakStuff&quot;&gt;My breaking Sample Code on GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hope this helps!&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2016/03/23/debugging-dotnet-based-windows-error-reports/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/03/23/debugging-dotnet-based-windows-error-reports</guid>
                <pubDate>Wed, 23 Mar 2016 23:55:00 +0000</pubDate>
        </item>

        <item>
                <title>XML Autocompletion with AvalonEdit</title>
                <description>
&lt;h2 id=&quot;avalonedit&quot;&gt;AvalonEdit&lt;/h2&gt;

&lt;p&gt;AvalonEdit is a text editor WPF control, used and created by the &lt;a href=&quot;http://www.icsharpcode.net/OpenSource/SD/Default.aspx&quot;&gt;SharpDevelop team&lt;/a&gt;. It comes with some nice features, like code folding support, text highlighting and infrastructure for advanced features like autocompletion.&lt;/p&gt;

&lt;p&gt;Read more about AvalonEdit on the &lt;a href=&quot;http://avalonedit.net/&quot;&gt;offical site&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To install AvalonEdit, just create a WPF project and install the &lt;a href=&quot;https://www.nuget.org/packages/AvalonEdit/&quot;&gt;AvalonEdit NuGet package&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;our-scenario&quot;&gt;Our Scenario&lt;/h2&gt;

&lt;p&gt;We use AvalonEdit to edit XML configurations, but it can be used with any language. This blogpost will only take a look at our XML-scenario.&lt;/p&gt;

&lt;h2 id=&quot;xml-autocomplete-or-intellisense&quot;&gt;XML Autocomplete or “IntelliSense”&lt;/h2&gt;

&lt;p&gt;AvalonEdit only ships with Syntax-Highlighting for XML - but nothing more. To get something like Tag-Autocompletion or even something like “IntelliSense” I had to combine different code pieces and write something new. So… the daily business of any programmer.&lt;/p&gt;

&lt;h3 id=&quot;xml-tag-completion---with-code-from-sharpdevelop-and-xsemmel&quot;&gt;XML Tag-Completion - with Code from SharpDevelop and Xsemmel&lt;/h3&gt;

&lt;p&gt;Modern text editors will autocomplete given XML tags, e.g. if I type the closing element for “&amp;lt;foo” it will create something like “&lt;foo&gt;&lt;/foo&gt;” and set the cursor inside the element.
To get to this feature we need to know which XML tag we are currently try to write - this issue can be solved with some magic RegEx0.&lt;/p&gt;

&lt;p&gt;The good part: This is already a solved problem. I discovered a very clever XmlParser on the &lt;strong&gt;&lt;a href=&quot;https://github.com/icsharpcode/SharpDevelop/tree/master/src/AddIns/DisplayBindings/XmlEditor&quot;&gt;SharpDevelop GitHub Repo&lt;/a&gt;&lt;/strong&gt; and another one from the &lt;strong&gt;&lt;a href=&quot;https://xsemmel.codeplex.com/&quot;&gt;Xsemmel Project&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I use code from both projects and integrated it in my sample project. And I hope I didn’t break the license by doing it - if yes I did it unintentional. Each code part is marked with the source and the copyright notes are included as well.&lt;/p&gt;

&lt;p&gt;Anyway: &lt;strong&gt;Huge credits are going to both projects.&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;what-i-get-from-those-libraries&quot;&gt;What I get from those libraries?&lt;/h3&gt;

&lt;p&gt;Both libraries are clever enough to parse XML - or even “invalid” XML, and return the current position inside the XML tree. The code from Xsemmel also helped me with the “pure” tag completion.&lt;/p&gt;

&lt;p&gt;My merged XmlParser will return me the needed information for autocompletion or even “IntelliSense”-like features.&lt;/p&gt;

&lt;h3 id=&quot;xml-intellisense---whats-the-source-of-the-intellisense&quot;&gt;XML “IntelliSense” - What’s the source of the “IntelliSense”?&lt;/h3&gt;

&lt;p&gt;To present some clever autocomplete actions, we need a source for this information. The good thing about XML is, that there is a huge range of related standards around it. The idea is simple:&lt;/p&gt;

&lt;p&gt;Using an &lt;strong&gt;existing XML Schema&lt;/strong&gt; should do the trick. I already blogged about it &lt;strong&gt;&lt;a href=&quot;http://blog.codeinside.eu/2016/03/06/parsing-xml-schemas-in-dotnet/&quot;&gt;here&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;putting-those-pieces-together&quot;&gt;Putting those pieces together:&lt;/h3&gt;

&lt;p&gt;I created a WPF project, included the AvalonEdit NuGet package and the code portions I already mentioned. The performance in the animation is a bit slow, because I wanted to show you what the XmlParser is doing in the background - this can be seen at the bottom of the application.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-03-13/xmleditor.gif&quot; alt=&quot;x&quot; title=&quot;AvalonEdit with XML Autocompletion&quot; /&gt;.&lt;/p&gt;

&lt;p&gt;You don’t need to “query” the document everytime you change the cursor - so in real life the performance hit is not very noticeable.&lt;/p&gt;

&lt;p&gt;As I already mentioned in the XSD-blogpost: XML Namespaces will not work with this implementation. As far as I know the SharpDevelop code should understand namespaces, but at least my XSD parser is not smart enough.&lt;/p&gt;

&lt;h3 id=&quot;the-logic&quot;&gt;The logic&lt;/h3&gt;

&lt;p&gt;The most interesting logic happens in the &lt;a href=&quot;https://github.com/Code-Inside/Samples/blob/master/2016/XmlIntelliSense/XmlIntelliSense.App/MainWindow.xaml.cs#L40&quot;&gt;TextEntered-EventHandler&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The “&amp;gt;” and “/” key is interesting for the simple tag autocompletion. The “XsdParser”-Result is used when you hit the “&amp;lt;” key or “ “ as long as you are inside a tag for attribute autocompletion.&lt;/p&gt;

&lt;h3 id=&quot;good-enough&quot;&gt;“Good enough”&lt;/h3&gt;

&lt;p&gt;My implementation is far away from perfection, but should be good enough for most simple cases. As I already mentioned, the heavy lifting is done by code from SharpDevelop or Xsemmel. My sample is self-contained and only relies on the AvalonEdit NuGet package and the standard WPF.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://github.com/Code-Inside/Samples/tree/master/2016/XmlIntelliSense&quot;&gt;Full Sample Code on GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hope this helps!&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2016/03/13/xml-autocompletion-with-avalonedit/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/03/13/xml-autocompletion-with-avalonedit</guid>
                <pubDate>Sun, 13 Mar 2016 22:00:00 +0000</pubDate>
        </item>

        <item>
                <title>Parsing XML Schemas in .NET</title>
                <description>
&lt;h2 id=&quot;xml-schemas&quot;&gt;XML Schemas&lt;/h2&gt;

&lt;p&gt;XML can be very verbose and seems to be old-fashioned, but the good part around XML is, that there is a hugh pile of standardized mechanics around it. 
To query XML documents you can use &lt;a href=&quot;https://en.wikipedia.org/wiki/XPath&quot;&gt;XPath&lt;/a&gt;, for transforming &lt;a href=&quot;https://en.wikipedia.org/wiki/XSLT&quot;&gt;XSLT&lt;/a&gt; and for validation &lt;strong&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/XML_Schema_(W3C)&quot;&gt;XML Schemas&lt;/a&gt;&lt;/strong&gt; or in short a “XSD” (XML Schema Definition).&lt;/p&gt;

&lt;h2 id=&quot;parsing-the-xsd-tree&quot;&gt;Parsing the XSD Tree&lt;/h2&gt;

&lt;p&gt;A XSD is just a XML document itself that describes the your valid XML document tree. Because its just a normal XML document (with a fancy XML-namespace), you could parse it via the normal XDocument, but things are way easier for you when you look at the &lt;a href=&quot;https://msdn.microsoft.com/de-de/library/system.xml.schema(v=vs.110).aspx&quot;&gt;System.Xml.Schema-Namespace&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;code&quot;&gt;Code&lt;/h2&gt;

&lt;p&gt;The basic code was taken from &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/ms255932(v=vs.110).aspx&quot;&gt;the MSDN&lt;/a&gt; and I added the recursive part to get all possible elements.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/// &amp;lt;summary&amp;gt;
/// Code based on https://msdn.microsoft.com/en-us/library/ms255932(v=vs.110).aspx
/// &amp;lt;/summary&amp;gt;
class Program
{
    public static void AnalyseSchema(XmlSchemaSet set)
    {
        // Retrieve the compiled XmlSchema object from the XmlSchemaSet
        // by iterating over the Schemas property.
        XmlSchema customerSchema = null;
        foreach (XmlSchema schema in set.Schemas())
        {
            customerSchema = schema;
        }

        // Iterate over each XmlSchemaElement in the Values collection
        // of the Elements property.
        foreach (XmlSchemaElement element in customerSchema.Elements.Values)
        {
            RecursiveElementAnalyser(&quot; &quot;, element);
        }

    }

    public static void RecursiveElementAnalyser(string prefix, XmlSchemaElement element)
    {
        string elementName = prefix + element.Name;

        string dataType = element.ElementSchemaType.TypeCode.ToString();

        Console.WriteLine(elementName + &quot; (&quot; + dataType + &quot;)&quot;);

        // Get the complex type of the Customer element.
        XmlSchemaComplexType complexType = element.ElementSchemaType as XmlSchemaComplexType;

        if (complexType != null)
        {
            // If the complex type has any attributes, get an enumerator 
            // and write each attribute name to the console.
            if (complexType.AttributeUses.Count &amp;gt; 0)
            {
                IDictionaryEnumerator enumerator =
                    complexType.AttributeUses.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    XmlSchemaAttribute attribute =
                        (XmlSchemaAttribute)enumerator.Value;

                    string attrDataType = attribute.AttributeSchemaType.TypeCode.ToString();

                    string attrName = string.Format(prefix + &quot;(Attr:: {0}({1}))&quot;, attribute.Name, attrDataType);

                    Console.WriteLine(attrName);
                }
            }

            // Get the sequence particle of the complex type.
            XmlSchemaSequence sequence = complexType.ContentTypeParticle as XmlSchemaSequence;

            if (sequence != null)
            {
                // Iterate over each XmlSchemaElement in the Items collection.
                foreach (var childElement in sequence.Items)
                {
                    var xmlSchemaElement = childElement as XmlSchemaElement;
                    if (xmlSchemaElement != null)
                    {
                        RecursiveElementAnalyser(&quot; &quot; + prefix, xmlSchemaElement);
                    }
                    else
                    {
                        // support for XmlSchemaChoise element list
                        var choice = childElement as XmlSchemaChoice;
                        if (choice != null)
                        {
                            foreach (var choiceElement in choice.Items)
                            {
                                var xmlChoiceSchemaElement = choiceElement as XmlSchemaElement;
                                if (xmlChoiceSchemaElement != null)
                                {
                                    RecursiveElementAnalyser(&quot; &quot; + prefix, xmlChoiceSchemaElement);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    static void Main(string[] args)
    {
        XmlSchemaSet schemas = new XmlSchemaSet();
        schemas.Add(&quot;&quot;, XmlReader.Create(new StringReader(File.ReadAllText(&quot;Schema.xsd&quot;))));
        schemas.Compile();
        AnalyseSchema(schemas);
        Console.ReadLine();
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-03-06/xsd.png&quot; alt=&quot;x&quot; title=&quot;XSD Tree from Code&quot; /&gt;&lt;/p&gt;

&lt;p&gt;You should see the possible XML elements, attributes and their datatypes, but you have access to all specified schema information from the XSD that you want.&lt;/p&gt;

&lt;h2 id=&quot;xml-namespaces&quot;&gt;XML Namespaces&lt;/h2&gt;

&lt;p&gt;XML namespaces are powerful, but can also be pretty complicated for everyone who needs to parse your XML. I guess you could put some evil XML namespaces inside the XSD and things will break with my code. 
Just be aware of this issue if you are dealing with namespaces.&lt;/p&gt;

&lt;h2 id=&quot;visual-studio-tooling&quot;&gt;Visual Studio Tooling&lt;/h2&gt;

&lt;p&gt;I discovered that Visual Studio ships with a pretty nice XSD editor. But you don’t need to craft the XSD by hand,there are many tools out there that can generate XSDs based on existing XML documents.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-03-06/vs.png&quot; alt=&quot;x&quot; title=&quot;Visual Studio XSD Tree&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;sample-xsd&quot;&gt;Sample XSD&lt;/h2&gt;

&lt;p&gt;I added the XSD Sample from the &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/bb675181.aspx&quot;&gt;MSDN&lt;/a&gt; in the demo project. If you found an issue, just let me know.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://github.com/Code-Inside/Samples/tree/master/2016/XsdParser&quot;&gt;Full Sample Code on GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hope this helps!&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2016/03/06/parsing-xml-schemas-in-dotnet/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/03/06/parsing-xml-schemas-in-dotnet</guid>
                <pubDate>Sun, 06 Mar 2016 08:15:00 +0000</pubDate>
        </item>

        <item>
                <title>Using FontAwesome in UWP apps</title>
                <description>
&lt;h2 id=&quot;fontawesome-in-wpf-and-fonts-in-uwp&quot;&gt;FontAwesome in WPF and Fonts in UWP&lt;/h2&gt;

&lt;p&gt;I blogged about &lt;a href=&quot;http://blog.codeinside.eu/2015/01/07/using-fontawesome-with-wpf/&quot;&gt;how to use FontAwesome in WPF&lt;/a&gt; last year and wrote a short blogpost about the nice &lt;a href=&quot;http://blog.codeinside.eu/2016/01/31/working-with-fonticons-in-uwp/&quot;&gt;FontIcon class in UWP&lt;/a&gt;. 
With the help of the FontIcon class I could include the FontAwesome glyphs, but working with the unicodes is not very dev friendly.&lt;/p&gt;

&lt;h2 id=&quot;bringing-fontawesomewpf-to-the-uwp-universe---oss-rocks&quot;&gt;Bringing FontAwesome.WPF to the UWP universe - OSS rocks!&lt;/h2&gt;

&lt;p&gt;The goal was pretty clear: I would like to have the excellent FontAwesome.WPF NuGet package working on UWP. 
So I created an issue on the &lt;a href=&quot;https://github.com/charri/Font-Awesome-WPF/issues/230&quot;&gt;FontAwesome.WPF GitHub repo&lt;/a&gt; and some contributions later the &lt;a href=&quot;http://www.nuget.org/packages/FontAwesome.UWP/&quot;&gt;FontAwesome.UWP NuGet package&lt;/a&gt; was born.&lt;/p&gt;

&lt;p&gt;_Thanks to everyone who was involved!__&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-03-05/nuget.png&quot; alt=&quot;x&quot; title=&quot;FontAwesome.UWP NuGet package&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;using-fontawesome-in-uwp&quot;&gt;Using FontAwesome in UWP…&lt;/h2&gt;

&lt;p&gt;As you might imaging - the usage is now pretty easy after including the FontAwesome.UWP NuGet package.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;Page
    x:Class=&quot;UwpDemo.MainPage&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    xmlns:local=&quot;using:UwpDemo&quot;
    xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
    xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
    xmlns:fa=&quot;using:FontAwesome.UWP&quot;
    mc:Ignorable=&quot;d&quot;&amp;gt;

    &amp;lt;Grid Background=&quot;{ThemeResource ApplicationPageBackgroundThemeBrush}&quot;&amp;gt;
        &amp;lt;fa:FontAwesome Icon=&quot;Flag&quot; FontSize=&quot;90&quot; Foreground=&quot;Chartreuse&quot; HorizontalAlignment=&quot;Center&quot; /&amp;gt;
    &amp;lt;/Grid&amp;gt;
&amp;lt;/Page&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Result:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-03-05/demo.png&quot; alt=&quot;x&quot; title=&quot;FontAwesome on UWP&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Pretty nice and it was a good collaboration - big thanks to &lt;a href=&quot;https://github.com/charri&quot;&gt;Thomas Charriere&lt;/a&gt;, who is the maintainer behind the project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://github.com/Code-Inside/Samples/tree/master/2016/UwpFontAwesome/UwpDemo&quot;&gt;Demo Project on our GitHub Sample repo&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hope this helps!&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2016/03/05/using-fontawesome-in-uwp-apps/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/03/05/using-fontawesome-in-uwp-apps</guid>
                <pubDate>Sat, 05 Mar 2016 23:55:00 +0000</pubDate>
        </item>

        <item>
                <title>Using Travis CI for GitHub Pages builds</title>
                <description>
&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-03-03/travisci.png&quot; alt=&quot;x&quot; title=&quot;Travis CI Logo&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;short-recap-github-pages--jekyll&quot;&gt;Short recap: GitHub Pages &amp;amp; Jekyll&lt;/h2&gt;

&lt;p&gt;This blog is powered by &lt;a href=&quot;https://pages.github.com/&quot;&gt;GitHub Pages&lt;/a&gt;, which uses &lt;a href=&quot;https://jekyllrb.com/&quot;&gt;Jekyll&lt;/a&gt; in the background. Jekyll is a static website generator, which means that this page is “build” and has no server-side rendering logic when you hit the page - it’s pure static HTML, CSS and JS.&lt;/p&gt;

&lt;p&gt;You could run Jekyll on your local box and publish the sites to GitHub Pages - I prefer a pure “GitHub Page”-based model. Actually I don’t even have Jekyll installed on my PC. &lt;a href=&quot;http://blog.codeinside.eu/2014/09/13/How-We-Moved-From-Wordpress-To-Jekyll-On-Windows/&quot;&gt;I wrote a small blogpost about running Jekyll on Windows if you are interested&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;travis-ci&quot;&gt;&lt;strong&gt;&lt;a href=&quot;http://travis-ci.org&quot;&gt;Travis CI&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;As you might imaging - during the build stuff can break. In this case GitHub will send you a very short “error” email via mail. To get a more detailed report, &lt;a href=&quot;https://help.github.com/articles/viewing-jekyll-build-error-messages/&quot;&gt;GitHub suggests to use Travis CI&lt;/a&gt;, which is the main topic of this blogpost.&lt;/p&gt;

&lt;h2 id=&quot;travis-ci-setup&quot;&gt;Travis CI Setup&lt;/h2&gt;

&lt;p&gt;The basic setup is pretty simple, but I had some issues - the last step is not very good documented - and that’s why I decided to blog about it.&lt;/p&gt;

&lt;h3 id=&quot;1-login-to-travis-ci-and-sync-your-account&quot;&gt;1. Login to Travis CI and “sync” your account&lt;/h3&gt;

&lt;p&gt;You will need to login to Travis CI with your GitHub account. This will kick in a “sync”. After a short period you should see all your repositories on your profile page:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-03-03/travisci-1.png&quot; alt=&quot;x&quot; title=&quot;Travis CI Profile Page&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;2-enable-the-desired-project-on-travis-ci&quot;&gt;2. Enable the desired project on Travis CI&lt;/h3&gt;

&lt;p&gt;Just flip on the switch on your profil page for the desired project and Travis will watch the repository for any changes.&lt;/p&gt;

&lt;h3 id=&quot;3-adding-a-gemfile-and-a-travisyml-file-to-your-project&quot;&gt;3. Adding a Gemfile and a .travis.yml file to your project&lt;/h3&gt;

&lt;p&gt;To build GitHub Page stuff via Travis you will need a &lt;a href=&quot;https://github.com/Code-Inside/Blog/blob/gh-pages/Gemfile&quot;&gt;Gemfile&lt;/a&gt; and a &lt;a href=&quot;https://github.com/Code-Inside/Blog/blob/gh-pages/.travis.yml&quot;&gt;.tarvis.yml&lt;/a&gt;.
My current files are pretty basic and a copy from the GitHub Pages Help site, with &lt;strong&gt;one important exception&lt;/strong&gt;…&lt;/p&gt;

&lt;h3 id=&quot;4-targeting-the-correct-branch&quot;&gt;4. Targeting the correct branch&lt;/h3&gt;

&lt;p&gt;The last step is to ensure that Travis CI will search for the correct branch. In my case, I only have the “gh-pages” branch, but Travis CI will look for a “master” branch.&lt;/p&gt;

&lt;p&gt;To configure Travis CI to use the correct “gh-pages” branch you will need this config section inside the .yml:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;branches:
 only:
 - gh-pages  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After this setup you should already see the finished Travis CI build:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-03-03/travisci-2.png&quot; alt=&quot;x&quot; title=&quot;Travis CI Build Page&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; The output of the build will not be copied over to GitHub - at this stage it is just a “safety net”. If you want to publish from Travis CI, there are many blogposts out there that describe this topic.&lt;/p&gt;

&lt;p&gt;Hope this helps!&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2016/03/03/using-travis-ci-for-github-page-builds/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/03/03/using-travis-ci-for-github-page-builds</guid>
                <pubDate>Thu, 03 Mar 2016 23:30:00 +0000</pubDate>
        </item>

        <item>
                <title>Pretty Print XML in .NET</title>
                <description>
&lt;h2 id=&quot;pretty-print&quot;&gt;Pretty Print&lt;/h2&gt;

&lt;p&gt;The term “pretty print” describes that a document is more or less human readable formatted. So instead of this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;Foo&amp;gt;&amp;lt;Bar&amp;gt;&amp;lt;Buzz&amp;gt;&amp;lt;/Buzz&amp;gt;&amp;lt;/Bar&amp;gt;&amp;lt;/Foo&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You might want to get this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;Foo&amp;gt;
  &amp;lt;Bar&amp;gt;
    &amp;lt;Buzz&amp;gt;&amp;lt;/Buzz&amp;gt;
  &amp;lt;/Bar&amp;gt;
&amp;lt;/Foo&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Many editors support this feature - but we want to do it in code.&lt;/p&gt;

&lt;h2 id=&quot;pretty-print-xml-with-net&quot;&gt;Pretty Print XML with .NET&lt;/h2&gt;

&lt;p&gt;The code is really simple, because XDocument does the heavy lifting for us.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var xDocument = XDocument.Parse(input);
string formattedXml = xDocument.ToString();

// Force XML Declaration if present
if (xDocument.Declaration != null)
{
  formattedXml = xDocument.Declaration + Environment.NewLine + formattedXml;
}
return formattedXml;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This should work in most cases - there might be some issues with comments or maybe special XML chars. If you have a better idea, please let me know.&lt;/p&gt;

&lt;p&gt;Hope this helps!&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2016/02/28/pretty-print-xml-in-dotnet/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/02/28/pretty-print-xml-in-dotnet</guid>
                <pubDate>Sun, 28 Feb 2016 20:00:00 +0000</pubDate>
        </item>

        <item>
                <title>ExpensiveMeeting - a Universal Windows Platform OSS app using Template10</title>
                <description>
&lt;h2 id=&quot;expensivemeeting&quot;&gt;ExpensiveMeeting&lt;/h2&gt;

&lt;p&gt;The app - which is just a fun project and shouldn’t be taken too seriously -  is like a stopwatch for meetings. 
But instead of the pure time it shows you also the burned money for your meeting, because time is money, right?&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2016-02-28/app.png&quot; alt=&quot;x&quot; title=&quot;ExpensiveMeeting app&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Don’t worry: The app is free and no ads are shown.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://www.microsoft.com/store/apps/9NBLGGH5PVW9&quot;&gt;Windows Store Download&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2 id=&quot;behind-the-scenes-universal-windows-platfrom-uwp&quot;&gt;Behind the scenes: Universal Windows Platfrom (UWP)&lt;/h2&gt;

&lt;p&gt;The app itself is a UWP app, which means it runs on Windows 10, Windows IoT, Windows Mobile 10 (or is it Phone?) and maybe in the future on Xbox One. 
To see the app running on my phone, without touching the code at all, was pure fun. I really like the UWP approach.&lt;/p&gt;

&lt;h2 id=&quot;behind-the-scenes-template10&quot;&gt;Behind the scenes: Template10&lt;/h2&gt;

&lt;p&gt;Starting from scratch can be fun, but to shorten the development time I used the nice &lt;strong&gt;&lt;a href=&quot;http://aka.ms/template10&quot;&gt;Template10&lt;/a&gt;&lt;/strong&gt; template, which gives me the typical hamburger app layout. 
The project can be found on &lt;a href=&quot;https://github.com/Windows-XAML/Template10&quot;&gt;GitHub&lt;/a&gt; and has a very active community.&lt;/p&gt;

&lt;h2 id=&quot;behind-the-scenes-all-code-on-github&quot;&gt;Behind the scenes: All Code on GitHub&lt;/h2&gt;

&lt;p&gt;I decided to work in the open on &lt;strong&gt;&lt;a href=&quot;https://github.com/Code-Inside/ExpensiveMeeting&quot;&gt;GitHub&lt;/a&gt;&lt;/strong&gt;, so if you are interested on the actual code, just take a look and do whatever you want to do.&lt;/p&gt;

&lt;p&gt;If you have ideas or found bugs I would appreciate your help:
Just create an &lt;strong&gt;&lt;a href=&quot;https://github.com/Code-Inside/ExpensiveMeeting/issues&quot;&gt;issue&lt;/a&gt;&lt;/strong&gt; or send a pull request.&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2016/02/28/expensivemeeting-a-uwp-oss-app-using-template10/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/02/28/expensivemeeting-a-uwp-oss-app-using-template10</guid>
                <pubDate>Sun, 28 Feb 2016 17:00:00 +0000</pubDate>
        </item>

        <item>
                <title>Shipping Visual C++ 2015 redistributable DLLs with your app or how to do an app-local deployment</title>
                <description>
&lt;h2 id=&quot;small-warning-im-not-a-c-dev&quot;&gt;Small warning: I’m not a C++ dev&lt;/h2&gt;

&lt;p&gt;We use VC++ just for a very small part of our application, but this part needs the VC++ 2015 runtime “installed” on the client, but we don’t want the UAC install dialog. 
So - let’s take a look how we can solve this problem.&lt;/p&gt;

&lt;p&gt;And if I write something stupid here - please let me know.&lt;/p&gt;

&lt;h2 id=&quot;ways-to-deploy-vc-2015&quot;&gt;Ways to deploy VC++ 2015&lt;/h2&gt;

&lt;p&gt;There are three ways to deploy the runtime:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Install it via the standalone VCRedist installer. This is probably the most known way, but requires elevated permissions because the file will be installed to System32.&lt;/li&gt;
  &lt;li&gt;Install it via a merge module. If you already have an installer, you can include the needed .msm files in your own installer, but this will also require elevated permissions because the files will be also installed to System32.&lt;/li&gt;
  &lt;li&gt;Deploy it with your app as app-local deployment. We will cover this in this blogpost, because &lt;strong&gt;we don’t want to touch anything that needs elevated permissions&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to read more about the first two ways, the &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/ms235299.aspx&quot;&gt;MSDN&lt;/a&gt; might be a good place to start.&lt;/p&gt;

&lt;h2 id=&quot;app-local-deployment-of-the-vc-2015-runtime&quot;&gt;App-Local deployment of the VC++ 2015 runtime&lt;/h2&gt;

&lt;p&gt;All what you need is already (if you are using Windows 10 &amp;amp; Visual Studio 2015) installed on your dev machine. Otherwise you will need to download the Windows 10 SDK and Visual Studio 2015.&lt;/p&gt;

&lt;p&gt;Depending on your application, you will need to ship &lt;strong&gt;all&lt;/strong&gt; dlls from the following folders with your application (= the dll/exe/whatever that needs the runtime) :&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;x86 applications&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\x86&lt;/li&gt;
  &lt;li&gt;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\x86\Microsoft.VC140.CRT&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;x64 applications&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\x64&lt;/li&gt;
  &lt;li&gt;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\x64\Microsoft.VC140.CRT&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;a href=&quot;https://blogs.msdn.microsoft.com/vcblog/2015/03/03/introducing-the-universal-crt/&quot;&gt;“Universal CRT”&lt;/a&gt; consists of many dlls and all are required. You have to copy them to your application folder and it should just work.&lt;/p&gt;

&lt;p&gt;As far as I know, if a user has installed the runtime via VCRedist or the merge modules the files inside System32 will be picked.&lt;/p&gt;

&lt;p&gt;I found this solution &lt;a href=&quot;https://social.msdn.microsoft.com/Forums/sqlserver/en-US/d8f0acf9-5d4c-408d-8cea-c201fd61b9b7/local-deployment-of-redist-dlls-no-longer-works-with-visual-studio-2015?forum=visualstudiogeneral&quot;&gt;here&lt;/a&gt; and it seems to work just fine - no UAC prompt. Yay.&lt;/p&gt;

&lt;p&gt;Hope this helps.&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2016/02/23/ship-vcredist-2015-with-your-app-aka-applocal-deploy/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/02/23/ship-vcredist-2015-with-your-app-aka-applocal-deploy</guid>
                <pubDate>Tue, 23 Feb 2016 22:45:00 +0000</pubDate>
        </item>

        <item>
                <title>Working with FontIcons in UWP</title>
                <description>
&lt;h2 id=&quot;fonticons-in-uwp&quot;&gt;FontIcons in UWP&lt;/h2&gt;

&lt;p&gt;Microsoft ships one builtin UWP (Universal Windows Platform) &lt;a href=&quot;https://msdn.microsoft.com/EN-US/library/windows/apps/windows.ui.xaml.controls.symbol.aspx&quot;&gt;&lt;strong&gt;SymbolIcon&lt;/strong&gt;&lt;/a&gt; class.&lt;/p&gt;

&lt;p&gt;The good thing about such FontIcons is, that you can scale and change the appearances very nice and don’t need a bunch of image assets for your icons.&lt;/p&gt;

&lt;p&gt;The down side is, that those icons are just a font… so no multicolor option.&lt;/p&gt;

&lt;p&gt;The builtin SymbolIcon usage is pretty easy:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;SymbolIcon Symbol=&quot;Accept&quot; /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;using-fonticon-to-serve-other-font-eg-fontawesome&quot;&gt;Using FontIcon to serve other font e.g. FontAwesome&lt;/h2&gt;

&lt;p&gt;Microsoft ships another simple class, the &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.fonticon.glyph&quot;&gt;&lt;strong&gt;FontIcon&lt;/strong&gt;&lt;/a&gt; class.&lt;/p&gt;

&lt;h3 id=&quot;including-the-font&quot;&gt;Including the font&lt;/h3&gt;

&lt;p&gt;You will need the actual Font-File, e.g. a .otf file. This file must be included in your project as &lt;strong&gt;Content&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;After that the usage is pretty simple if you know the correct syntax:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;FontIcon FontFamily=&quot;./fontawesome.otf#FontAwesome&quot; Glyph=&quot;&amp;amp;#xf0b2;&quot;&amp;gt;&amp;lt;/FontIcon&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The Glyph-Property is the HexCode for the target char.&lt;/p&gt;

&lt;p&gt;Pretty important, but I’m not a Font-Expert, so maybe this is “normal”&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The #FontAwesome must be set.&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;In XAML the Glyph must be in this form&lt;/p&gt;

    &lt;p&gt;“”&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;From Code, the value must be unicode, e.g.&lt;/p&gt;

    &lt;p&gt;Test.Glyph = “\uf0b2”;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of the “./…” path syntax you could also use something like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;FontIcon FontFamily=&quot;ms-appx:///fontawesome.otf#FontAwesome&quot; Glyph=&quot;&amp;amp;#xf0b2;&quot;&amp;gt;&amp;lt;/FontIcon&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;result&quot;&gt;Result&lt;/h2&gt;

&lt;p&gt;The result is hopefully that you see the correct icon… right?&lt;/p&gt;

&lt;p&gt;BTW, we try to bring &lt;a href=&quot;https://github.com/charri/Font-Awesome-WPF/issues/23&quot;&gt;FontAwesome to UWP&lt;/a&gt; with a simple NuGet package.&lt;/p&gt;

&lt;p&gt;And thanks to &lt;a href=&quot;https://twitter.com/Alex_Witkowski/status/692134058051178502&quot;&gt;Alexander Witkowski&lt;/a&gt; for the suggestion of the FontIcon class - I didn’t know that this is part of the SDK.&lt;/p&gt;

&lt;h2 id=&quot;demo-code&quot;&gt;Demo-Code&lt;/h2&gt;

&lt;p&gt;I made a pretty small UWP Demo, which can be viewed on our &lt;a href=&quot;https://github.com/Code-Inside/Samples/tree/master/2016/FontAwesomeDemo&quot;&gt;Samples-Repo&lt;/a&gt;.&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2016/01/31/working-with-fonticons-in-uwp/</link>
                <guid>https://oliverguhr.github.io/Blog//2016/01/31/working-with-fonticons-in-uwp</guid>
                <pubDate>Sun, 31 Jan 2016 20:30:00 +0000</pubDate>
        </item>

        <item>
                <title>Serving embedded resources with ASP.NET WebApi</title>
                <description>
&lt;h2 id=&quot;embedded-files-why&quot;&gt;Embedded files? Why?&lt;/h2&gt;

&lt;p&gt;In a normal Web-Application all files are somehow stored as files in the app directory, but sometimes it could be handy to embed those files.&lt;/p&gt;

&lt;p&gt;One scenario could be that you have a “library”, which can be integrated in a larger application. If you don’t want to pull over all files and you &lt;strong&gt;just want to expose a single assembly&lt;/strong&gt; (for example as NuGet package) embedded resources might come handy.&lt;/p&gt;

&lt;h2 id=&quot;demo-application&quot;&gt;Demo-Application&lt;/h2&gt;

&lt;p&gt;My demo application is a simple ConsoleApp, which a selfhosting WebAPI and two Controllers (Demo and Pages):&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2015-12-31/embeddedresources-structure.png&quot; alt=&quot;x&quot; title=&quot;VS Structure&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Important is, that my “target” html and css file are marked as &lt;strong&gt;Embedded Resource&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;routing&quot;&gt;Routing&lt;/h2&gt;

&lt;p&gt;In my sample I have created on “PageController”, which accepts all requests that seems to target the embedded files.&lt;/p&gt;

&lt;p&gt;Registration:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;public class Startup
{
    public void Configuration(IAppBuilder appBuilder)
    {
        HttpConfiguration config = new HttpConfiguration();

        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: &quot;ApiV1&quot;,
            routeTemplate: &quot;api/v1/{controller}/{id}&quot;,
            defaults: new { id = RouteParameter.Optional }
            );

        config.Routes.MapHttpRoute(
           name: &quot;PageController&quot;,
           routeTemplate: &quot;{*anything}&quot;,
           defaults: new { controller = &quot;Page&quot;, uri = RouteParameter.Optional });

        appBuilder.UseWebApi(config);
    }

}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;the-pagecontroller&quot;&gt;The “PageController”&lt;/h2&gt;

&lt;p&gt;This controller will try to read the HTTP GET PathAndQuery and will look inside the assembly resources for something with the same name.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;public class PageController : ApiController
{
    private const string ResourcePath = &quot;SelfHostWithBetterRouting.Pages{0}&quot;;

    public static string GetStreamContent(string folderAndFileInProjectPath)
    {
        var asm = Assembly.GetExecutingAssembly();
        var resource = string.Format(ResourcePath, folderAndFileInProjectPath);

        using (var stream = asm.GetManifestResourceStream(resource))
        {
            if (stream != null)
            {
                var reader = new StreamReader(stream);
                return reader.ReadToEnd();
            }
        }
        return String.Empty;
    }


    public HttpResponseMessage Get()
    {
        var virtualPathRoot = this.Request.GetRequestContext().VirtualPathRoot;
        string filename = this.Request.RequestUri.PathAndQuery;

        // remove SERVER/appname from request to get the relative filename
        if (virtualPathRoot != &quot;/&quot;)
        {
            filename = filename.ToLowerInvariant().Replace(virtualPathRoot.ToLowerInvariant(), string.Empty);
        }
        
        // input as /page-assets/js/scripts.js
        if (filename == &quot;/&quot; || filename == &quot;&quot;)
        {
            filename = &quot;.index.html&quot;;
        }

        // folders will be seen as &quot;namespaces&quot; - so replace / with the .
        filename = filename.Replace(&quot;/&quot;, &quot;.&quot;);
        // resources can't be named with -, so it will be replaced with a _
        filename = filename.Replace(&quot;-&quot;, &quot;_&quot;);

        var mimeType = System.Web.MimeMapping.GetMimeMapping(filename);

        var fileStreamContent = GetStreamContent(filename);

        if (string.IsNullOrWhiteSpace(fileStreamContent))
        {
            throw new Exception(string.Format(&quot;Can't find embedded file for '{0}'&quot;, filename));
        }

        if (virtualPathRoot != &quot;/&quot;)
        {
            fileStreamContent = fileStreamContent.Replace(&quot;~/&quot;, virtualPathRoot + &quot;/&quot;);
        }
        else
        {
            fileStreamContent = fileStreamContent.Replace(&quot;~/&quot;, virtualPathRoot);
        }

        var response = new HttpResponseMessage();
        response.Content = new StringContent(fileStreamContent);
        response.Content.Headers.ContentType = new MediaTypeHeaderValue(mimeType);
        return response;
    }

}	
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;mix-the-pagecontroller-and-normal-webapi-controllers&quot;&gt;Mix the “PageController” and normal WebAPI Controllers&lt;/h2&gt;

&lt;p&gt;In my sample the “PageController” will catch all requests that are not handled by other controllers, so you could even serve a general 404 page.&lt;/p&gt;

&lt;h2 id=&quot;hosting-in-iis&quot;&gt;Hosting in IIS&lt;/h2&gt;

&lt;p&gt;If you host this inside an IIS it will not work out of the box, because the IIS itself tries to serve static content. One easy option would be to include this inside your web.config:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;!-- prevent IIS from serving embeddded stuff --&amp;gt;
&amp;lt;location path=&quot;pages&quot;&amp;gt;
    &amp;lt;system.webServer&amp;gt;
        &amp;lt;handlers&amp;gt;
            &amp;lt;add name=&quot;nostaticfile&quot; path=&quot;*&quot; verb=&quot;GET&quot; type=&quot;System.Web.Handlers.TransferRequestHandler&quot; preCondition=&quot;integratedMode,runtimeVersionv4.0&quot; /&amp;gt;
        &amp;lt;/handlers&amp;gt;
    &amp;lt;/system.webServer&amp;gt;
&amp;lt;/location&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With this web.config setting in place the request should route through your code.&lt;/p&gt;

&lt;h2 id=&quot;result&quot;&gt;Result&lt;/h2&gt;

&lt;p&gt;The self hosting WebAPI returns the “index.html” and the linked “site.css” - all embedded inside the assembly:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2015-12-31/embeddedresources-result.png&quot; alt=&quot;x&quot; title=&quot;Result of Democode&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In an &lt;a href=&quot;http://blog.codeinside.eu/2015/09/29/wpf-chrome-embedded-and-webapi-selfhosting/&quot;&gt;older blogpost&lt;/a&gt; I used a similar approach, but the routing part is now “better” solved.&lt;/p&gt;

&lt;p&gt;Hope this helps!&lt;/p&gt;

&lt;p&gt;The code is also available on &lt;strong&gt;&lt;a href=&quot;https://github.com/Code-Inside/Samples/tree/master/2015/SelfHostWithBetterRoutingForEmbeddedResources&quot;&gt;GitHub&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2015/12/31/serving-embedded-resources-with-aspnet-webapi/</link>
                <guid>https://oliverguhr.github.io/Blog//2015/12/31/serving-embedded-resources-with-aspnet-webapi</guid>
                <pubDate>Thu, 31 Dec 2015 13:45:00 +0000</pubDate>
        </item>

        <item>
                <title>Working with JumpLists in WPF Apps</title>
                <description>
&lt;h2 id=&quot;jumplists&quot;&gt;JumpLists?&lt;/h2&gt;

&lt;p&gt;JumpLists were introduced with Windows 7 and if it they are implemented right are pretty handy, because it can provide common functionality.&lt;/p&gt;

&lt;p&gt;A real world example:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2015-11-30/jumplistdemo.png&quot; alt=&quot;x&quot; title=&quot;JumpList Demo&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;jumplists-with-net&quot;&gt;JumpLists with .NET&lt;/h2&gt;

&lt;p&gt;In pre .NET 4.0 times there was a Windows7API Code Pack available to access the JumpLists APIs of Windows and many older blogposts reference it, but since .NET 4.0 is out the JumpList APIs are part of the &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/system.windows.shell.jumpitem(v=vs.110).aspx&quot;&gt;PresentationFramework.dll&lt;/a&gt;. 
So, you don’t need any other library - at least not for the stuff that I want to show you here.&lt;/p&gt;

&lt;h2 id=&quot;jumplists--windows-vista&quot;&gt;JumpLists &amp;amp; Windows Vista&lt;/h2&gt;

&lt;p&gt;A warning for everyone that still have to support Windows Vista: .NET 4.0 is supported on Windows Vista, but the JumpLists were introduced with Windows 7.
If you are trying to create a JumpList or touch the JumpList APIs your app will crash with a NotSupportedException.&lt;/p&gt;

&lt;h2 id=&quot;creating-jumplists-via-xaml&quot;&gt;Creating JumpLists via XAML&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Small warning: If you try this on Windows Vista, your app will just crash…&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JumpLists are registred per application and the easiest way to create a (static) JumpList is via XAML in the App.xaml:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;Application x:Class=&quot;Jumplist_Sample.App&quot;
            xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
            xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
            StartupUri=&quot;MainWindow.xaml&quot;&amp;gt;
    &amp;lt;Application.Resources&amp;gt;
        
    &amp;lt;/Application.Resources&amp;gt;
    &amp;lt;JumpList.JumpList&amp;gt;
        &amp;lt;JumpList ShowRecentCategory=&quot;True&quot;
                ShowFrequentCategory=&quot;True&quot;
                
                JumpItemsRejected=&quot;JumpList_JumpItemsRejected&quot;
                JumpItemsRemovedByUser=&quot;JumpList_JumpItemsRemovedByUser&quot;&amp;gt;
            
            &amp;lt;JumpTask Title=&quot;Notepad&quot; 
                    Description=&quot;Open Notepad.&quot; 
                    ApplicationPath=&quot;C:\Windows\notepad.exe&quot;
                    IconResourcePath=&quot;C:\Windows\notepad.exe&quot;/&amp;gt;
            &amp;lt;JumpTask Title=&quot;Read Me&quot; 
                    Description=&quot;Open readme.txt in Notepad.&quot; 
                    ApplicationPath=&quot;C:\Windows\notepad.exe&quot;
                    IconResourcePath=&quot;C:\Windows\System32\imageres.dll&quot;
                    IconResourceIndex=&quot;14&quot;
                    WorkingDirectory=&quot;C:\Users\Public\Documents&quot;
                    Arguments=&quot;readme.txt&quot;/&amp;gt;
        &amp;lt;/JumpList&amp;gt;
    &amp;lt;/JumpList.JumpList&amp;gt;
&amp;lt;/Application&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;creating-jumplists-via-code&quot;&gt;Creating JumpLists via Code&lt;/h2&gt;

&lt;p&gt;The “coding” JumpList API is a bit odd to use, but still easy to understand:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var jt = new JumpTask
{
    ApplicationPath = &quot;C:\\Windows\\notepad.exe&quot;,
    Arguments = &quot;readme.txt&quot;,
    Title = &quot;Recent Entry for Notepad&quot;,
    CustomCategory = &quot;Dummy&quot;
};

JumpList.AddToRecentCategory(jt);



var jt2 = new JumpTask
{
    ApplicationPath = &quot;C:\\Windows\\notepad.exe&quot;,
    Arguments = &quot;readme.txt&quot;,
    Title = &quot;Code Entry for Notepad&quot;,
    CustomCategory = &quot;Dummy&quot;
};

var currentJumplist = JumpList.GetJumpList(App.Current);
currentJumplist.JumpItems.Add(jt2);
currentJumplist.Apply();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The “Apply()” call is needed, otherwise the new JumpItem will not be added. As you can see, you can create new JumpList entries, add (and I think you could also remove items) from the default recent category.
Besides &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/system.windows.shell.jumptask(v=vs.110).aspx&quot;&gt;JumpTasks&lt;/a&gt; there is &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/system.windows.shell.jumppath(v=vs.110).aspx&quot;&gt;JumpPath&lt;/a&gt;, which just contains a link.&lt;/p&gt;

&lt;p&gt;In the XAML Part I also hooked up some events, so your application can get notified when a user pins something or removes something which you might want to handle.&lt;/p&gt;

&lt;h2 id=&quot;result&quot;&gt;Result&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2015-11-30/jumplistresult.png&quot; alt=&quot;x&quot; title=&quot;Result of Democode&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Oh… and of course: Windows 10 still supports JumpLists and there are rumors that even UWP apps will somehow support JumpLists.&lt;/p&gt;

&lt;p&gt;A good read was &lt;a href=&quot;http://elegantcode.com/2011/01/21/wpf-windows-7-taskbar-part-two-jump-lists/&quot;&gt;this blogpost&lt;/a&gt; (and it also contains information about other Windows 7 “Taskbar”-enhancements which are still valid for Windows 10).&lt;/p&gt;

&lt;p&gt;Hope this helps!&lt;/p&gt;

&lt;p&gt;The code is also available on &lt;strong&gt;&lt;a href=&quot;https://github.com/Code-Inside/Samples/tree/master/2015/Jumplists&quot;&gt;GitHub&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2015/11/30/working-with-jumplists-in-wpf-apps/</link>
                <guid>https://oliverguhr.github.io/Blog//2015/11/30/working-with-jumplists-in-wpf-apps</guid>
                <pubDate>Mon, 30 Nov 2015 23:30:00 +0000</pubDate>
        </item>

        <item>
                <title>XML deserialize to abstract class, interface or base class</title>
                <description>
&lt;p&gt;Let’s assume we have the following XML structure:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&amp;gt;
&amp;lt;Root&amp;gt;
  &amp;lt;Node&amp;gt;
    &amp;lt;Label Id=&quot;Label1&quot;&amp;gt;Betreff&amp;lt;/Label&amp;gt;
    &amp;lt;TextBox Id=&quot;TextBox1&quot; MultiLines=&quot;3&quot; /&amp;gt;
  &amp;lt;/Node&amp;gt;
  &amp;lt;Node&amp;gt;
    &amp;lt;Label Id=&quot;Label2&quot;&amp;gt;Betreff 123132&amp;lt;/Label&amp;gt;
    &amp;lt;TextBox Id=&quot;TextBox2&quot; /&amp;gt;
    &amp;lt;Button Id=&quot;Button1&quot; Label=&quot;Hello World&quot; Action=&quot;Foobar&quot; /&amp;gt;
  &amp;lt;/Node&amp;gt;
&amp;lt;/Root&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Under &lt;Root&gt; we have n-&lt;Node&gt;-elements and each &lt;Node&gt; element has a couple of specialized elements. The elements share a common attribute, in this case &quot;Id&quot;, so we could say that we need a &quot;Base&quot;-Element.&lt;/Node&gt;&lt;/Node&gt;&lt;/Root&gt;&lt;/p&gt;

&lt;h2 id=&quot;code-deserialize-the-elements--co&quot;&gt;Code: Deserialize the elements &amp;amp; co.&lt;/h2&gt;

&lt;p&gt;The first step: We need to deserialize the &lt;Root&gt; and it's &lt;Node&gt; children.&lt;/Node&gt;&lt;/Root&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;public class Root
{
    [XmlElement(ElementName = &quot;Node&quot;)]
    public List&amp;lt;Node&amp;gt; Nodes { get; set; }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Next - and this is the &lt;strong&gt;main part of this blogpost&lt;/strong&gt; - we need to describe the &lt;Node&gt; element and that it contains a list of &quot;baseelements&quot;.&lt;/Node&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;public class Node
{
    [XmlElement(typeof(LabelElement), ElementName = &quot;Label&quot;)]
    [XmlElement(typeof(TextBoxElement), ElementName = &quot;TextBox&quot;)]
    [XmlElement(typeof(ButtonElement), ElementName = &quot;Button&quot;)]
    public List&amp;lt;BaseElement&amp;gt; Elements { get; set; }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As you can see, we need to “register” each specialized known element. The default XmlSerializer will read all XmlElement Attributes and will do the main work.&lt;/p&gt;

&lt;p&gt;The last part: The base class and the specialized classes for each element.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;public abstract class BaseElement
{
    [XmlAttribute(AttributeName = &quot;Id&quot;)]
    public string Id { get; set; }
}

public class ButtonElement : BaseElement
{
    [XmlAttribute(AttributeName = &quot;Label&quot;)]
    public string Label { get; set; }

    [XmlAttribute(AttributeName = &quot;Action&quot;)]
    public string Action { get; set; }
}

public class LabelElement : BaseElement
{
    [XmlText]
    public string Content { get; set; }
}

public class TextBoxElement : BaseElement
{
    [XmlAttribute(AttributeName = &quot;MultiLines&quot;)]
    public int MultiLines { get; set; }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;interfaces-base-classes-etc&quot;&gt;Interfaces, base classes etc.&lt;/h2&gt;

&lt;p&gt;It doesn’t matter if you choose a interface, base class or a abstract base class. The built-in XmlSerializer is flexible, but as far as I know you will need to “register” the implementation elements on the base element. So there is no “convention” or any magic in place.&lt;/p&gt;

&lt;h2 id=&quot;using-the-code&quot;&gt;Using the code&lt;/h2&gt;

&lt;p&gt;Using the XmlSerializer is simple:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;FileStream readFileStream = new FileStream(@&quot;test.xml&quot;, FileMode.Open, FileAccess.Read, FileShare.Read);

XmlSerializer serializer = new XmlSerializer(typeof(Root));
var test = serializer.Deserialize(readFileStream);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2015-10-25/result.PNG&quot; alt=&quot;x&quot; title=&quot;Xml Deserializer&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;serializing&quot;&gt;Serializing&lt;/h2&gt;

&lt;p&gt;If you want to serialize objects to XML with this code the XmlSerializer should be well prepared and no code changes should be needed. It just works ;)&lt;/p&gt;

&lt;p&gt;Hope this helps!&lt;/p&gt;

&lt;p&gt;The code is also available on &lt;strong&gt;&lt;a href=&quot;https://github.com/Code-Inside/Samples/tree/master/2015/XmlBaseClassDeserializer&quot;&gt;GitHub&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2015/10/25/xml-deserialize-to-abstract-class-interface-or-base-class/</link>
                <guid>https://oliverguhr.github.io/Blog//2015/10/25/xml-deserialize-to-abstract-class-interface-or-base-class</guid>
                <pubDate>Sun, 25 Oct 2015 22:00:00 +0000</pubDate>
        </item>

        <item>
                <title>Nothing to do next weekend? Come to Leipzig and join the Developer Open Space 2015</title>
                <description>
&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2015-10-14/dos.png&quot; alt=&quot;x&quot; title=&quot;Developer Open Space&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The Developer Open Space is not a typical developer conference: There are &lt;strong&gt;no&lt;/strong&gt; fixed speakers or topics, just many other tech lovers who wants to &lt;strong&gt;learn&lt;/strong&gt; or &lt;strong&gt;share&lt;/strong&gt; &lt;strong&gt;their&lt;/strong&gt; knowledge.&lt;/p&gt;

&lt;p&gt;The Open Space was started in 2009 and was more or less Microsoft-centric, but times are changing and the technology discussions on previous Open Spaces spread to all different kinds of technology - from fancy Web, to DevOps, Functional Programming, IoT etc.&lt;/p&gt;

&lt;p&gt;But it is not just technology: If you want to talk about Soft-Skills or want to hear how other developers do their jobs just join the Developer Open Space.
Even if you want to talk about how you craft your own beer: I bet you will find your audience ;)&lt;/p&gt;

&lt;p&gt;Sounds good, right? Just visit the &lt;strong&gt;&lt;a href=&quot;https://devopenspace.de/&quot;&gt;official website&lt;/a&gt;&lt;/strong&gt; for more information. I will be there from Saturday to Sunday :)&lt;/p&gt;

&lt;h2 id=&quot;key-facts&quot;&gt;Key Facts&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;No fixed agenda or speakers&lt;/li&gt;
  &lt;li&gt;If you have a topic to talk about: Just do it&lt;/li&gt;
  &lt;li&gt;You are a part of this “conference”&lt;/li&gt;
  &lt;li&gt;Location: Leipzig, Germany&lt;/li&gt;
  &lt;li&gt;Date: 16.10 - 18.10.2015&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;a href=&quot;https://devopenspace.de/&quot;&gt;Official Website&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
                <link>https://oliverguhr.github.io/Blog//2015/10/14/developer-open-space/</link>
                <guid>https://oliverguhr.github.io/Blog//2015/10/14/developer-open-space</guid>
                <pubDate>Wed, 14 Oct 2015 23:30:00 +0000</pubDate>
        </item>

        <item>
                <title>WPF, Chrome Embedded and WebApi Self-hosted</title>
                <description>
&lt;p&gt;Building “rich desktop clients” is not a very easy task. WPF can be a good choice for “fat” Windows Apps, but if you have zero knowledge in XAML you might end up in hell, because… XAML, right? If you are more a “web guy” (like myself) or just want to reuse existing code from your Web-App and want to stick to your .NET know-how this blogpost might come handy.&lt;/p&gt;

&lt;h2 id=&quot;cross-platfrom&quot;&gt;Cross Platfrom?&lt;/h2&gt;

&lt;p&gt;If you want to go &lt;strong&gt;real cross platform&lt;/strong&gt; and don’t have any issues with Javascript there are other options available: &lt;strong&gt;&lt;a href=&quot;http://nwjs.io/&quot;&gt;nw.js&lt;/a&gt;&lt;/strong&gt; or for more advanced use cases &lt;strong&gt;&lt;a href=&quot;http://electron.atom.io/&quot;&gt;Electron&lt;/a&gt;&lt;/strong&gt;. Both frameworks seems like a good starting point, but in a “Windows Only”-environment (well… this might be a bet on the future…) or with an existing large .NET code base not the ideal solution.&lt;/p&gt;

&lt;h2 id=&quot;the-idea&quot;&gt;The idea&lt;/h2&gt;

&lt;p&gt;So, back to .NET land and the idea is clever and kinda stupid together: We want to build a small app that embeds a browser &lt;strong&gt;and&lt;/strong&gt; a server (this is more or less the same trick from Electron &amp;amp; co.).
The host should be a WPF application, because with this we could combine interesting frameworks in one application - e.g. legacy code stuff, WPF controls, web stuff… yeah!&lt;/p&gt;

&lt;h2 id=&quot;building-blocks-the-browser&quot;&gt;Building blocks: The Browser&lt;/h2&gt;

&lt;p&gt;If you just want to display “Web-Content” you can just use the &lt;strong&gt;&lt;a href=&quot;https://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser(v=vs.110).aspx&quot;&gt;built-in WebBrowser-Control&lt;/a&gt;&lt;/strong&gt;. The most common and annoying problem is that the default rendering engine is stuck in the stone age: Internet Explorer 7. Even on Windows 10 the default rendering engine will be set to IE7.
To fix this you can use some &lt;a href=&quot;https://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version&quot;&gt;Registry-Magic&lt;/a&gt;, but this is not very elegant.&lt;/p&gt;

&lt;p&gt;A better solution would be to take a deeper look at the &lt;a href=&quot;https://github.com/cefsharp/CefSharp&quot;&gt;Chromium Embedded Framework for .NET&lt;/a&gt;. It is the rendering engine of Chrome - which gives you a super powerful platform - and is super easy to use.
The only downside: You need to &lt;a href=&quot;https://github.com/cefsharp/CefSharp/issues/576#issuecomment-61926661&quot;&gt;compile your app for x86 or x64 - AnyCPU won’t work&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So… let’s take a look how we can achieve our goal.&lt;/p&gt;

&lt;h2 id=&quot;building-blocks-the-server&quot;&gt;Building blocks: The Server&lt;/h2&gt;

&lt;p&gt;A good option is using the HttpListener with the ASP.NET WebApi - of course you could also use NancyFx or any other OWIN/”self-host” web framework. The hosting application will use the HttpListener from your System and will listen to a specific port. As long as you use a high port number you don’t need admin privileges.&lt;/p&gt;

&lt;p&gt;For the demo I embedded the HTML inside the application, but this could be read from a resource file or any other storage in real life.&lt;/p&gt;

&lt;p&gt;As far as I know maybe you could also do some other hosting tricks, so that the application doesn’t really needs to listen to a specific port, e.g. hosting the stuff in-memory.&lt;/p&gt;

&lt;h2 id=&quot;code-server-part&quot;&gt;Code: Server Part&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The (important) Server Parts:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;public partial class App : Application
{
    public App()
    {
        string baseAddress = &quot;http://localhost:9000/&quot;;

        webApp = WebApp.Start&amp;lt;Startup&amp;gt;(url: baseAddress);
       
    }

    public IDisposable webApp { get; set; }

    ~App()
    {
        webApp.Dispose();
    }
}

public class Startup
{
    // This code configures Web API. The Startup class is specified as a type
    // parameter in the WebApp.Start method.
    public void Configuration(IAppBuilder appBuilder)
    {
        // Configure Web API for self-host. 
        HttpConfiguration config = new HttpConfiguration();

        DefaultConnectWebApiConfig.Register(config);

        appBuilder.UseWebApi(config);
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;The controller code: Simple ApiController which reads a embedded HTML file.&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;public class DemoController : ApiController
{
    private const string ResourcePath = &quot;SelfHostAndCef.HtmlSamples.{0}&quot;;
    public static string GetTestFileContent(string folderAndFileInProjectPath)
    {
        var asm = Assembly.GetExecutingAssembly();
        var resource = string.Format(ResourcePath, folderAndFileInProjectPath);

        using (var stream = asm.GetManifestResourceStream(resource))
        {
            if (stream != null)
            {
                var reader = new StreamReader(stream);
                return reader.ReadToEnd();
            }
        }
        return String.Empty;
    }

    public HttpResponseMessage Get()
    {
        var response = new HttpResponseMessage();
        response.Content = new StringContent(GetTestFileContent(&quot;demo.html&quot;));
        response.Content.Headers.ContentType = new MediaTypeHeaderValue(&quot;text/html&quot;);
        return response;
    }

}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;code-the-browser&quot;&gt;Code: The Browser&lt;/h2&gt;

&lt;p&gt;This is more or less the &lt;strong&gt;&lt;a href=&quot;https://github.com/cefsharp/CefSharp.MinimalExample/&quot;&gt;“minimal cef” sample&lt;/a&gt;&lt;/strong&gt;, but for the sample it is good enough:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;Window x:Class=&quot;SelfHostAndCef.DialogWindow&quot;
        xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
        xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
        xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
        xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
        xmlns:local=&quot;clr-namespace:SelfHostAndCef&quot;
        xmlns:wpf=&quot;clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf&quot;
        mc:Ignorable=&quot;d&quot;
        Title=&quot;DialogWindow&quot; Height=&quot;300&quot; Width=&quot;300&quot;&amp;gt;
    &amp;lt;Grid&amp;gt;
        &amp;lt;Grid.RowDefinitions&amp;gt;
            &amp;lt;RowDefinition /&amp;gt;
            &amp;lt;RowDefinition Height=&quot;Auto&quot; /&amp;gt;
        &amp;lt;/Grid.RowDefinitions&amp;gt;
        &amp;lt;wpf:ChromiumWebBrowser x:Name=&quot;Browser&quot; Grid.Row=&quot;0&quot;
                          WebBrowser=&quot;{Binding WebBrowser, Mode=OneWayToSource}&quot;
                          Title=&quot;{Binding Title, Mode=TwoWay}&quot; /&amp;gt;
        &amp;lt;StatusBar Grid.Row=&quot;1&quot;&amp;gt;
            &amp;lt;ProgressBar HorizontalAlignment=&quot;Right&quot;
                         IsIndeterminate=&quot;{Binding WebBrowser.IsLoading}&quot;
                         Width=&quot;100&quot;
                         Height=&quot;16&quot;
                         Margin=&quot;3&quot; /&amp;gt;
            &amp;lt;Separator /&amp;gt;
            &amp;lt;!-- TODO: Could show hover link URL here --&amp;gt;
            &amp;lt;TextBlock /&amp;gt;
        &amp;lt;/StatusBar&amp;gt;
    &amp;lt;/Grid&amp;gt;
&amp;lt;/Window&amp;gt;

public partial class DialogWindow : Window
{
    public DialogWindow()
    {
        InitializeComponent();
        this.Browser.Address = &quot;http://localhost:9000/api/v1/Demo&quot;;

        var hostElement = new SampleWebViewHost();
        this.Browser.RegisterJsObject(&quot;sampleWebViewHost&quot;, hostElement);

        hostElement.SampleWebViewHostInvoked += HostElementSampleWebViewHostInvoked;
    }

    private void HostElementSampleWebViewHostInvoked(object sender, SampleWebViewHostEventArgs e)
    {
        Dispatcher.Invoke(() =&amp;gt;
        {
            this.DialogResult = true;
            this.Close();
        });
    }   
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;code-the-html&quot;&gt;Code: The HTML&lt;/h2&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang=&quot;en&quot;&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset=&quot;UTF-8&quot;&amp;gt;
    &amp;lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&amp;gt;
    &amp;lt;title&amp;gt;Example Form&amp;lt;/title&amp;gt;
    &amp;lt;script type=&quot;text/javascript&quot; src=&quot;https://code.jquery.com/jquery-2.1.4.min.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;h1&amp;gt;SampleForm&amp;lt;/h1&amp;gt;
&amp;lt;form&amp;gt;
    &amp;lt;label&amp;gt;HelloWorld:&amp;lt;/label&amp;gt;
    &amp;lt;input name=&quot;test&quot;/&amp;gt;
    &amp;lt;button type=&quot;submit&quot;&amp;gt;OK&amp;lt;/button&amp;gt;
&amp;lt;/form&amp;gt;
&amp;lt;script&amp;gt;
    $(document).ready(function() {
        $(&quot;form&quot;).submit(function() {

            var result = JSON.stringify($(&quot;form&quot;).serializeArray());

            if (sampleWebViewHost != null) {
                sampleWebViewHost.done(result);
            }

            return false;
        });

    });
&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;building-blocks-browser-to-app-communication&quot;&gt;Building blocks: Browser-to-App communication&lt;/h2&gt;

&lt;p&gt;There are several ways how to interact between the hosting app and the web-app. One way is via URLs or using standard web methods. If you host the server component, then you can invoke anything inside your app.
Another solution would be to register a “scriptable” Javascript object inside the Browser-Control. I already blogged about the &lt;a href=&quot;http://blog.codeinside.eu/2013/09/04/interaktionen-zwischen-web-und-windows-desktopwindows-phonewinrt-mit-objectforscripting-window-external-notify/&quot;&gt;“window.external” api&lt;/a&gt; (in German). With this “scriptable” object in place you can call .NET functions from Javascript or the other way around.&lt;/p&gt;

&lt;h2 id=&quot;the-full-lifecycle&quot;&gt;The full lifecycle&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Application starts and “self-hosts” the WebApi and listens on Port 9000&lt;/li&gt;
  &lt;li&gt;WPF Window is displayed with a large button&lt;/li&gt;
  &lt;li&gt;The Button will invoke the actual WebBrowser Control and set up a “scriptable” Javascript object&lt;/li&gt;
  &lt;li&gt;User fills in the desired data, press OK inside the WebBrowser and sends the data (in this case) to the WebBrowser-Host via the “scriptable” Javascript object&lt;/li&gt;
  &lt;li&gt;Our technology mix is complete: We can host our own WebApp inside our WinApp&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://oliverguhr.github.io/Blog/assets/md-images/2015-09-29/demo.gif&quot; alt=&quot;x&quot; title=&quot;Demo&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;tldr&quot;&gt;TL;DR&lt;/h2&gt;

&lt;p&gt;Ok… as I told you this blogpost shows you a really stupid or really clever trick (it depends on your habbits… WebGuy vs. WindowsGuy).
In this example we used a self-hosting WebApi to display an embedded HTML page via CEF Sharp inside a Windows App.&lt;/p&gt;

&lt;p&gt;It’s magic, right?&lt;/p&gt;

&lt;p&gt;The full code can be found on &lt;strong&gt;&lt;a href=&quot;https://github.com/Code-Inside/Samples/tree/master/2015/SelfHostAndCef&quot;&gt;GitHub&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;
</description>
                <link>https://oliverguhr.github.io/Blog//2015/09/29/wpf-chrome-embedded-and-webapi-selfhosting/</link>
                <guid>https://oliverguhr.github.io/Blog//2015/09/29/wpf-chrome-embedded-and-webapi-selfhosting</guid>
                <pubDate>Tue, 29 Sep 2015 23:30:00 +0000</pubDate>
        </item>


</channel>
</rss>