<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="https://blog.dangl.me/rss/xslt"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Dangl.Blog();</title>
    <link>https://blog.dangl.me/</link>
    <description>Blogging about .Net, DevOps, Networking and BIM. Home of the free GAEB Converter.</description>
    <generator>Articulate, blogging built on Umbraco</generator>
    <item>
      <guid isPermaLink="false">1446</guid>
      <link>https://blog.dangl.me/archive/installing-net-9-alongside-older-versions-on-ubuntu-2204/</link>
      <category>DotNet</category>
      <title>Installing .NET 9 Alongside Older Versions on Ubuntu 22.04</title>
      <description>&lt;p&gt;With the recently release .NET 9, Microsoft has changed how they're publishing packages for Linux distributions. Previously, there was a Microsoft managed package repository available from which you could easily install different .NET versions, making it especially easy for CI agents to keep multiple .NET versions installed and updated.&lt;/p&gt;
&lt;p&gt;However, starting with .NET 9, Microsoft no longer provides a feed for their distributions. So if you need the SDK or just the runtime, you need to use a feed managed by Canonical (the company behind Ubuntu). The problem is, there's no feed on which you can get multiple versions, e.g. .NET 8 and .NET 9 combined. Also, you can't just install from two different repositories, since the packages will have mutually exclusive dependencies, prohibiting you from installing .NET 8 and 9 at the same time. Also, the Ubuntu repositories seem to be a bit behind, so you could have to wait up to one week to get the latest updates for your SDKs.&lt;br /&gt;I didn't properly dive into the reasons behind this change, I think it's mostly Microsoft wanting to integrate their .NET distribution into more official channels, but from a developer perspective, that doesn't seem very ideal for me.&lt;/p&gt;
&lt;p&gt;So, yesterday evening, I tried to figure out how to get .NET 9 running while keeping all the other versions installed. Even though they're out of support, sometimes you just need to update an on-off CLI tool with a bugfix or new feature without having to update the whole project and the CI pipeline. Also, since both .NET 8 and .NET 9 are still in active support, we plan to also run tests for our products on both - so having them all on our CI agents was required.&lt;/p&gt;
&lt;p&gt;There was no way that I found how to work with feeds, but luckily, you can just use the &lt;a href="https://learn.microsoft.com/en-us/dotnet/core/install/linux-scripted-manual#scripted-install" title="Scripted Install for DotNet" data-anchor="#scripted-install"&gt;dotnet-install.sh script for manual SDK installations&lt;/a&gt;. I found it pretty easy to use, but there's a gotcha: If you've already got some .NET versions installed, they're probably by default in a different directory than what the installation script uses. In that case, though, before installation, you can simply run &lt;span class="Code"&gt;dotnet --list-sdks&lt;/span&gt; to get an output like this:&lt;br /&gt;&lt;span class="Code"&gt;dotnet --list-sdks&lt;/span&gt;&lt;br /&gt;&lt;span class="Code"&gt;6.0.428 [/usr/share/dotnet/sdk]&lt;/span&gt;&lt;br /&gt;&lt;span class="Code"&gt;7.0.410 [/usr/share/dotnet/sdk]&lt;/span&gt;&lt;br /&gt;&lt;span class="Code"&gt;8.0.404 [/usr/share/dotnet/sdk]&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Here, we see that .NET is installed to &lt;span class="Code"&gt;/usr/share/dotnet&lt;/span&gt;, which we can then pass to the installation script as directory like this:&lt;br /&gt;&lt;span class="Code"&gt;./dotnet-install.sh --install-dir /usr/share/dotnet --channel 9.0&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Running &lt;span class="Code"&gt;dotnet --list-sdks&lt;/span&gt; again should now list .NET 9 as well, and you're good to go. There's no need to set any more environment variables. The only thing to keep in mind is that you now have to manually update .NET via the install script, since &lt;span class="Code"&gt;apt-get&lt;/span&gt; won't do those for the .NET 9 sdk now.&lt;/p&gt;
&lt;p&gt;Happy developing!&lt;/p&gt;</description>
      <pubDate>Fri, 29 Nov 2024 11:29:43 Z</pubDate>
      <a10:updated>2024-11-29T11:29:43Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1438</guid>
      <link>https://blog.dangl.me/archive/aspnet-core-locally-serving-outdated-dev-certificate/</link>
      <category>DotNet</category>
      <title>ASP.NET Core Locally Serving Outdated Dev Certificate</title>
      <description>&lt;p&gt;Today, I was trying to run one of our apps locally. It's a fairly small service, that's only receiving updates every few months, and all the testing and deployment happens in CI, so it hasn't been run locally for quite some time. But, when I started it, it tried to serve an expired certificate, so Chrome showed me a warning about the site not being secure.&lt;/p&gt;
&lt;p&gt;With ASP.NET Core, the development workflow is quite nice. You can easily use self signed certificates for working with localhost, and &lt;span class="Code"&gt;dotnet&lt;/span&gt; takes care of managing all that. Yet, somehow, it served me a certificate that expired almost three years ago. Even after regenerating the dev certificates locally, I had the same error, so I looked into the configuration.&lt;/p&gt;
&lt;p&gt;Turns out, I had this configuration option set in the user secrets on that machine: &lt;span class="Code"&gt;kestrel:certificates:development:password&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;User secrets are a way of managing not really sensitive but developer or machine specific configs for ASP.NET Core projects. The option above, with using a set password for a certificate, resulted in the app not automatically choosing the current dev certificate but instead one that expired long ago. So, quick fix when you know where to look😀&lt;/p&gt;
&lt;p&gt;Happy encrypting!&lt;/p&gt;</description>
      <pubDate>Wed, 17 May 2023 20:19:36 Z</pubDate>
      <a10:updated>2023-05-17T20:19:36Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1425</guid>
      <link>https://blog.dangl.me/archive/cancel-obsolete-http-requests-in-rxnet-with-the-switch-operator/</link>
      <category>DotNet</category>
      <title>Cancel Obsolete Http Requests in Rx.NET with the Switch Operator</title>
      <description>&lt;p&gt;Using Observables in Rx.NET is a super fun and efficient way to organize data flows in your applications. While it's widely used for front end development - it's basically a core part of Angular - it's actually a great library to use in any projects where you're using loosely coupled services and state management.&lt;/p&gt;
&lt;p&gt;One of these use cases is having a filtered list. Imagine you've got a small app that shows you some table, along with a single text field for filtering. Imagine also that this list is fed from some asynchronous source, so it's not an in memory filter operation but maybe the response from a Http call.&lt;/p&gt;
&lt;p&gt;Now, when you start typing in this box, what should happen? In the simplest case, without delays or checks, every letter typed in that filter box sends a Http request. That's probably a bit of an unoptimized approach, but it should work. This could look something like the following:&lt;/p&gt;
&lt;p&gt;&lt;code data-gist-id="3e87c41e0abf3b9ec79b99d7ad8db8e0" data-gist-file="first_approach.cs"&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;What's actually happening is that you're creating a stream of events in your code. Whenever you change the url, you're sending a request. When that request finishes, you're updating the list. The problem now comes when the requests don't come in the order they've been sent. Your user might have typed &lt;em&gt;pizza&lt;/em&gt;, deleted that and then again typed &lt;em&gt;pasta&lt;/em&gt;. If the first request, for really any reason, was delayed, you might have the situation where you're sowing &lt;em&gt;pizza&lt;/em&gt; results to &lt;em&gt;pasta &lt;/em&gt;guys!&lt;/p&gt;
&lt;p&gt;To resolve this, you want to track which requests have been sent and discard all but the latest one. In rxjs, you'd be using the &lt;span class="Code"&gt;switchMap&lt;/span&gt; operator. In Rx.NET, it's simply called &lt;span class="Code"&gt;Switch&lt;/span&gt; and expects you to either provide a &lt;span class="Code"&gt;Task&lt;/span&gt; or another &lt;span class="Code"&gt;IObservable&lt;/span&gt;:&lt;/p&gt;
&lt;p&gt;&lt;code data-gist-id="3e87c41e0abf3b9ec79b99d7ad8db8e0" data-gist-file="with_cancellation.cs"&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;What's happening here is that only the latest call will come through. So when you've got more than one request running at the same time, you're never again getting stale data.&lt;/p&gt;
&lt;p&gt;If you want to dive deeper into this, you can take a look at &lt;a href="https://github.com/GeorgDangl/LightQuery/blob/dev/src/LightQuery.Client/PaginationBaseService.cs#L104-L138" title="GitHub - GeorgDangl - LightQuery - PaginationBaseService" data-anchor="#L104-L138"&gt;the source code for LightQuery&lt;/a&gt;, which uses this approach in conjunction with &lt;span class="Code"&gt;CancellationToken&lt;/span&gt;s. I'd also like to thank Brandon for &lt;a href="https://stackoverflow.com/questions/17836743/how-to-cancel-a-select-in-rx-if-it-is-not-finished-before-the-next-event-arrives#answer-17837998" title="StackOverflow - How to cancel a Select in RX if it is not finished before the next event arrives" data-anchor="#answer-17837998"&gt;providing a great answer at StackOverflow&lt;/a&gt;, which really goes into detail!&lt;/p&gt;
&lt;p&gt;Hope you're going to have fun with Rx.NET!&lt;/p&gt;</description>
      <pubDate>Thu, 30 Jan 2020 19:51:54 Z</pubDate>
      <a10:updated>2020-01-30T19:51:54Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1424</guid>
      <link>https://blog.dangl.me/archive/accessing-the-revit-api-in-callbacks-from-other-threads/</link>
      <category>DotNet</category>
      <title>Accessing the Revit API in Callbacks from Other Threads</title>
      <description>&lt;p&gt;Just this week, I've been doing some work with a plugin for Autodesk Revit. The general idea of the plugin is to show a window which basically just wraps a Chromium embedded browser to display a web UI and interact with the Revit API. The interaction itself is pretty straightforward - with &lt;a href="https://github.com/cefsharp/CefSharp" title="GitHub - cefsharp - CefSharp"&gt;CefSharp&lt;/a&gt;, you can bind JavaScript objects in the browser to .NET objects in the plugin and thus access Revit features.&lt;/p&gt;
&lt;p&gt;We've implemented that by having a singleton on the .NET side that listens to commands from the browser. The first, possibly naive approach, was to simply call our code whenever we got a message:&lt;/p&gt;
&lt;p&gt;&lt;code data-gist-id="b40a23b441be1575ac169d99d11e9f44" data-gist-file="RevitApi_Throws.cs"&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;However, this didn't work. While all the data was transferred correctly, whenever we accessed certain features of the Revit API, we got a &lt;span class="Code"&gt;SEHException&lt;/span&gt; from unmanaged code in Revit. A quick Google search yielded this bit of info: &lt;em&gt;"SEHExceptions are always indications of a bug in Revit."&lt;/em&gt;. Ok, we thought, but that's super basic stuff we're accessing, there's probably not an undiscovered bug with Revit here.&lt;/p&gt;
&lt;p&gt;Luckily, debugging this gave us a bit more info: The API is working correctly when accessed from the main thread, but throws when accessed by another one. So even though we weren't doing any UI operations, this seemed to be the root cause of our issue. Since you also can't invoke something on the main thread in Revit, with &lt;span class="Code"&gt;Application.Current.Dispatcher&lt;/span&gt; not being set, we fell back to using the &lt;span class="Code"&gt;UIApplication.Idling&lt;/span&gt; event and a stack to invoke our methods on the main thread:&lt;/p&gt;
&lt;p&gt;&lt;code data-gist-id="b40a23b441be1575ac169d99d11e9f44" data-gist-file="RevitApi_Correct.cs"&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This cost us a few hours, so I hope it's helpful to others!&lt;/p&gt;
&lt;p&gt;Happy integrating!&lt;/p&gt;</description>
      <pubDate>Tue, 21 Jan 2020 11:41:25 Z</pubDate>
      <a10:updated>2020-01-21T11:41:25Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1423</guid>
      <link>https://blog.dangl.me/archive/handling-datetimeoffset-in-sqlite-with-entity-framework-core/</link>
      <category>DotNet</category>
      <title>Handling DateTimeOffset in SQLite with Entity Framework Core</title>
      <description>&lt;p&gt;Recently, ASP.NET Core 3.0 was released, along with all it's supporting libraries like Entity Framework Core. In the process of &lt;a href="https://www.dangl-it.com/products/danglidentity/" title="Dangl IT GmbH - Dangl.Identity"&gt;migrating Dangl.Identity&lt;/a&gt; over to the new version, I discovered that some integration tests failed with this message:&lt;/p&gt;
&lt;p&gt;&lt;span class="Code"&gt;System.NotSupportedException : SQLite cannot order by expressions of type 'DateTimeOffset'. Convert the values to a supported type or use LINQ to Objects to order the results.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The error message is pretty clear - SQLite with Entity Framework Core 3.0 does no longer support some operations when using &lt;span class="Code"&gt;DateTimeOffset&lt;/span&gt; properties in database models, as specified in the &lt;a href="https://docs.microsoft.com/en-us/ef/core/providers/sqlite/limitations#query-limitations" title="Microsoft Docs - SQLite Limitations" data-anchor="#query-limitations"&gt;official Microsoft Guidelines on limitations with SQLite&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The recommendation to switch to a supported type is great, but what to use? Falling back to regular &lt;span class="Code"&gt;DateTime&lt;/span&gt;, you'll lose the time zone information. Even if you're storing only UTC dates, while ensuring you're never making an error anywhere you touch dates, Entity Framework will always return a &lt;span class="Code"&gt;DateTimeKind.Unspecified&lt;/span&gt; when retrieving values from the database. While you can work around that with some conversion via an &lt;span class="Code"&gt;EntityMaterializerSource&lt;/span&gt;, this feels awkward and error prone.&lt;/p&gt;
&lt;p&gt;Luckily, aptly named &lt;a href="https://github.com/aspnet/EntityFrameworkCore/issues/10784#issuecomment-415769754" title="GitHub - EntityFrameworkCore - DateTimeOffset issue" data-anchor="#issuecomment-415769754"&gt;user bugproof on GitHub posted a great snippet&lt;/a&gt; that attaches a built-in converter for all properties in your database model. Here's how I've implemented it in my database context class:&lt;/p&gt;
&lt;p&gt;&lt;code data-gist-id="b90370124720ed8fed9539509aafd155" data-gist-file="DatabaseContext.cs"&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The only drawback is that the conversion only supports up to millisecond precision, but for most uses cases this is likely not a problem. In case you're comparing values, simply trim the last three digits from your values in your test code and you're good to go:&lt;/p&gt;
&lt;p&gt;&lt;code data-gist-id="b90370124720ed8fed9539509aafd155" data-gist-file="DateTimeOffsetTickSubtraction.cs"&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Happy modelling!&lt;/p&gt;</description>
      <pubDate>Tue, 15 Oct 2019 12:07:18 Z</pubDate>
      <a10:updated>2019-10-15T12:07:18Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1419</guid>
      <link>https://blog.dangl.me/archive/impact-of-o-n-runtime-in-practice-with-before-after-results/</link>
      <category>DotNet</category>
      <title>Impact of O(n²) Runtime in Practice - With Before &amp; After Results</title>
      <description>&lt;p&gt;With &lt;a href="https://www.dangl-it.com/products/avacloud-gaeb-saas/" title="Dangl IT GmbH - AVACloud"&gt;AVACloud&lt;/a&gt;, we're providing a hosted SaaS service for our &lt;a href="https://www.dangl-it.com/products/gaeb-ava-net-library/" title="Dangl IT GmbH - GAEB &amp;amp; AVA .Net Libraries"&gt;GAEB &amp;amp; AVA .Net Libraries&lt;/a&gt;, a project calculation module &amp;amp; data exchange format for the construction industry.&lt;/p&gt;
&lt;p&gt;Among the paid service, there are some free offerings for AVACloud for limited use cases. With that, users often convert from the various data formats to Excel. In our monitoring, we noticed some irregularities from the free service. Conversions usually take just tens or a few hundreds of milliseconds. But we had some that took about half an hour, way to long for any one user to be happy.&lt;/p&gt;
&lt;p&gt;Luckily, we've been contact by the user and were asked for assistance. After a bit of investigation and profiling, we quickly found the culprit - we had &lt;strong&gt;a part in the conversion process that had O(n²) runtime:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="display: block; margin-left: auto; margin-right: auto;" src="https://blog.dangl.me/media/1187/folie-01.png" alt="O(n²) algorithmic runtime in real life scenarios" data-udi="umb://media/2a8e82224a894533bb3f8adcaee30bd9" /&gt;&lt;/p&gt;
&lt;p&gt;The graph above shows the run time of the complete conversion process by the amount of elements within a parent container. It's a pretty nice O(n²) graph, at least visually, not so much for actual users😊&lt;/p&gt;
&lt;p&gt;The thing is, this wasn't really noticed anytime before. In practice, service specifications for construction projects look like this:&lt;/p&gt;
&lt;p&gt;&lt;img style="display: block; margin-left: auto; margin-right: auto;" src="https://blog.dangl.me/media/1190/project_structure.png" alt="Project structure of a service specification" data-udi="umb://media/35fa001899464104b06505354892f6cf" /&gt;&lt;/p&gt;
&lt;p&gt;So while real construction projects often have up to a few hundred of positions, sometimes even a few thousand, they're structured in a tree so that each container itself only has at most tens of child elements.&lt;/p&gt;
&lt;p&gt;The offending part of the code actually worked on the level of a single container. It did perform a validity check when adding a new element, by checking against all siblings. This wasn't a problem until one day, a customer had a single container with over 40.000 elements that really triggered this...&lt;/p&gt;
&lt;p&gt;The fix was rather easy, it basically just amounted to introducing a cache. And thus, the performance quickly became linear:&lt;/p&gt;
&lt;p&gt;&lt;img style="display: block; margin-left: auto; margin-right: auto;" src="https://blog.dangl.me/media/1188/folie-02.png" alt="Linear performance after switching from O(n²) to O(n) algorithm" data-udi="umb://media/90d69af56d96464d88e53fc38089f10c" /&gt;&lt;/p&gt;
&lt;p&gt;In that case, the dotted red line is the previous, O(n²) runtime, while blue represents the situation after the fix. Even more impressive is a zoomed view, which shows just how massive the difference from such an oversight can be:&lt;/p&gt;
&lt;p&gt;&lt;img style="display: block; margin-left: auto; margin-right: auto;" src="https://blog.dangl.me/media/1189/folie-03.png" alt="Zoomed view of new runtime behavior" data-udi="umb://media/8d89502da76e410ba38686a5905fc2f8" /&gt;&lt;/p&gt;
&lt;p&gt;In hindsight, the error was very obvious. It wasn't noticed because typical data sets were always small enough so this never really was a problem, until it one day was... Luckily, the fix could be implemented very quickly, and I got a satisfied user and some material for a blog post out of it😊&lt;/p&gt;
&lt;p&gt;Happy optimizing!&lt;/p&gt;</description>
      <pubDate>Fri, 14 Jun 2019 13:44:33 Z</pubDate>
      <a10:updated>2019-06-14T13:44:33Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1407</guid>
      <link>https://blog.dangl.me/archive/transform-your-aspnet-core-website-into-a-single-file-executable-desktop-app/</link>
      <category>DotNet</category>
      <title>Transform your ASP.NET Core Website into a Single File Executable Desktop App</title>
      <description>&lt;p&gt;Using web technologies to create desktop apps has been around for quite some time now, with frameworks like &lt;a href="https://electronjs.org/" title="Electron"&gt;Electron&lt;/a&gt; being mature and used in lots of products, such as Spotify and Slack. I've only ever used it for side projects, until finally this week a customer asked me if I could provide a desktop application of our popular &lt;a data-udi="umb://document/83feb7e86c454aeab940a924425cc23a" href="/archive/what-is-gaeb/" title="What is GAEB?"&gt;Web&lt;strong&gt;GAEB&lt;/strong&gt; converter&lt;/a&gt;. Of course I could! So I sat down at my computer and made an ASP.NET Core MVC app into a desktop app, bundled as a single executable file.&lt;/p&gt;
&lt;p&gt;This approach works by bundling everything together - your frontend, sometimes even your ASP.NET Core backend server and it's own embedded browser. This has been a bit polarizing in the last years among various communities. It's great for developer productivity, but it's also a very wasteful way to use a computers resources.&lt;/p&gt;
&lt;p&gt;However, I'm leaning heavily towards productivity to be able to quickly build features our users care about. I could have built a dedicated .NET WPF app from scratch, or I could just use Electron and be done in two hours. That's what I'd like to share with you in this blog post.&lt;/p&gt;
&lt;h2&gt;Build Script&lt;/h2&gt;
&lt;p&gt;The following is the complete build target for &lt;a data-udi="umb://document/091dd97b312a4a0a88fe8dc04c00a0f6" href="/archive/using-webdeploy-via-nuke-build-scripts/" title="Using WebDeploy via Nuke Build Scripts"&gt;Nuke Build&lt;/a&gt;. You're free to use something else to orchestrate your build, but even if you're unfamiliar with this tool, you'll see that it's quite straightforward:&lt;/p&gt;
&lt;p&gt;&lt;code data-gist-id="13b4f4674529772f3bf0d3ced5a6677e" data-gist-file="PublishElectronApp.cs"&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;I'll explain the script step-by-step, but I will skip the trivial parts, like copying the files to the output directory. If anything is unclear, please leave a comment!&lt;/p&gt;
&lt;h2&gt;Configure Electron.NET&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://github.com/ElectronNET/Electron.NET" title="Electron.NET"&gt;Electron.NET&lt;/a&gt; is an integration for the the Electron package with ASP.NET Core. It's got a great documentation at it's project site, so I'm not going to deeply into the details.&lt;/p&gt;
&lt;p&gt;When you set up your ASP.NET Core project, you're using the Electron.NET package to instrument the interaction with the Electron shell. The result will be a self contained deployment that bundles the Kestrel server into your app.&lt;/p&gt;
&lt;p&gt;&lt;code data-gist-id="13b4f4674529772f3bf0d3ced5a6677e" data-gist-file="PublishElectronApp.cs" data-gist-line="11"&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The Dangl.WebGAEB solution uses a &lt;span class="Code"&gt;Standalone&lt;/span&gt; configuration which sets up some things differently in contrast to the web deployment. For example, I'm using embedded services instead of calling a REST API. This heavily depends on your app as a whole and is not covered in this post.&lt;/p&gt;
&lt;h2&gt;Build a Single Executable File with Warp&lt;/h2&gt;
&lt;p&gt;While Electron itself is cool and all, it's Node.js heritage really shows: After the app is created, you'll have a folder with tons of files. This isn't a problem if you're doing some big business app with an installer, but I simply want a single executable file, &lt;span class="Code"&gt;.exe&lt;/span&gt; for Windows in my case. I remembered the &lt;a href="https://github.com/dgiagio/warp" title="GitHub - Warp"&gt;Warp project&lt;/a&gt;, which I've read about some time ago. This tool takes a folder, bundles it into a single executable file and lets you specify an entry point.&lt;/p&gt;
&lt;p&gt;&lt;code data-gist-id="13b4f4674529772f3bf0d3ced5a6677e" data-gist-file="PublishElectronApp.cs" data-gist-line="24-36"&gt;&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;Change the Generated Exe to Hide its Console Window&lt;/h2&gt;
&lt;p&gt;One drawback to this approach is that warp internally starts your ASP.NET Core application, which itself is a console host. The final Electron window is then again launched from your ASP.NET Core server. This means there will be an additional console window present, besides your app. This won't fly with users, so it has to be disabled.&lt;/p&gt;
&lt;p&gt;Truth is, I'm not really familiar with how this works. But there's some metadata in executable files on Windows. One of them is whether or not an &lt;span class="Code"&gt;.exe&lt;/span&gt; should show it's console host. Unfortunately, this isn't configurable until .NET Core 3.0, so we have to find another way. Fortunately, there's a great wiki page on the &lt;a href="https://github.com/AvaloniaUI/Avalonia/wiki/Hide-console-window-for-self-contained-.NET-Core-application" title="GitHub - AvaloniaUI"&gt;AvaloniaUI GitHub page&lt;/a&gt;. It's explain how the &lt;span class="Code"&gt;editbin.exe&lt;/span&gt; utility, which is included in Visual Studio, can be used to patch your executable. So just go find &lt;span class="Code"&gt;editbin.exe&lt;/span&gt; in your Visual Studio installation folder and you're good to go!&lt;/p&gt;
&lt;p&gt;&lt;code data-gist-id="13b4f4674529772f3bf0d3ced5a6677e" data-gist-file="PublishElectronApp.cs" data-gist-line="38-46"&gt;&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;Upload your Artifacts&lt;/h2&gt;
&lt;p&gt;Your final result will be a single executable file. Which contains your ASP.NET Core backend, the Kestrel webserver, your frontend, and last but not least, a full web browser. I see where the critics saying this is wasteful are coming from, but it just works amazingly well😊&lt;/p&gt;
&lt;p&gt;This example is pushing the artifacts, along with some documentation, to &lt;a href="https://docs.dangl-it.com/" title="DanglDocu - Dangl IT GmbH"&gt;Dangl&lt;strong&gt;Docu&lt;/strong&gt;&lt;/a&gt;. There, my customers get notified about new releases and can download it. For you, that's probably different!&lt;/p&gt;
&lt;p&gt;&lt;code data-gist-id="13b4f4674529772f3bf0d3ced5a6677e" data-gist-file="PublishElectronApp.cs" data-gist-line="51-57"&gt;&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;The Result&lt;/h2&gt;
&lt;p&gt;You can check out the &lt;a href="https://www.web-gaeb.de/" title="WebGAEB - Dangl IT GmbH"&gt;online version of Web&lt;strong&gt;GAEB&lt;/strong&gt;&lt;/a&gt;. It's basically the same as the &lt;a data-udi="umb://document/26371a3f96164b2eb78ef953e792764a" href="/gaeb-converter/" title="GAEB Converter"&gt;GAEB converter&lt;/a&gt; on this site, except it's in German. The cleverly named "Desktop Edition" looks like this and runs 100% locally:&lt;/p&gt;
&lt;p&gt;&lt;img style="display: block; margin-left: auto; margin-right: auto;" src="https://blog.dangl.me/media/1184/webgaebdesktop_sm.png" alt="" data-udi="umb://media/f7d170f5460c4c0b88f7cdba2060f7f3" /&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Happy packaging!&lt;/p&gt;</description>
      <pubDate>Thu, 21 Mar 2019 16:34:07 Z</pubDate>
      <a10:updated>2019-03-21T16:34:07Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1398</guid>
      <link>https://blog.dangl.me/archive/remove-duplicate-enum-entries-in-swagger-documents-with-nswag-in-aspnet-core/</link>
      <category>DotNet</category>
      <title>Remove Duplicate Enum Entries in Swagger Documents with NSwag in ASP.NET Core</title>
      <description>&lt;p&gt;&lt;a href="https://github.com/RSuter/NSwag" title="GitHub - RSuter - NSwag"&gt;NSwag&lt;/a&gt; and &lt;a href="https://github.com/RSuter/NJsonSchema" title="GitHub - RSuter - NJsonSchema"&gt;NJsonSchema&lt;/a&gt; are great tools that make it super easy to integrate &lt;a href="https://swagger.io" title="Swagger"&gt;Swagger / OpenAPI&lt;/a&gt; specification documents in your ASP.NET Core apps.&lt;/p&gt;
&lt;p&gt;Basically, you simply define your web server backend and then all your API endpoints and models are automatically available for anyone to generate clients in their favorite language.&lt;/p&gt;
&lt;p&gt;In such scenarios, NSwag is often configured to use a &lt;span class="Code"&gt;StringEnumConverter&lt;/span&gt;, meaning that enum values are meant to be serialized as strings when they're sent over the wire. However, there's one nasty thing that's allowed by the &lt;a href="https://stackoverflow.com/questions/15458101/can-you-have-multiple-enum-values-for-the-same-integer" title="StackOverflow - Multiple Enum Values for the same Integer in C#"&gt;C# specification&lt;/a&gt; when it comes to this:&lt;/p&gt;
&lt;p&gt;&lt;code data-gist-id="af167dd657b8f8b2879f8208341304a4" data-gist-file="HttpStatusCode.cs"&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;You might actually have two different string representations that both match an internally used integer identifier. That becomes a problem when you're using string serialization for enumerations but track them internally by their integer id.&lt;/p&gt;
&lt;p&gt;In NJsonSchema, for example, &lt;a href="https://github.com/RSuter/NJsonSchema/issues/800" title="GitHub - RSuter - NJsonSchema Issue with StringEnumConverter"&gt;there's a small bug&lt;/a&gt; that would lead to &lt;span class="Code"&gt;TemporaryRedirect&lt;/span&gt; being serialized twice in this case. That's sometimes not a problem, but strongly typed languages like C# or Java will fail to compile the generated client code.&lt;/p&gt;
&lt;p&gt;To solve this, you can simply remove these distinct values in a &lt;span class="Code"&gt;PostProcess&lt;/span&gt; action when you're setting up NSwag for your ASP.NET Core application:&lt;/p&gt;
&lt;p&gt;&lt;code data-gist-id="af167dd657b8f8b2879f8208341304a4" data-gist-file="NSwagPostProcess.cs"&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Happy serializing!&lt;/p&gt;</description>
      <pubDate>Thu, 03 Jan 2019 20:18:36 Z</pubDate>
      <a10:updated>2019-01-03T20:18:36Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1396</guid>
      <link>https://blog.dangl.me/archive/accessing-nuget-package-paths-in-your-net-sdk-based-csproj-files/</link>
      <category>DotNet</category>
      <title>Accessing NuGet Package Paths in Your .NET SDK Based csproj Files</title>
      <description>&lt;p&gt;With the switch to the SDK based *.csproj format for Visual Studio projects, the file format was greatly improved. &lt;a rel="noopener" href="https://github.com/NuGet/NuGet.Client/pull/2271" target="_blank" title="GitHub - NuGet Client - Pull Request 2271"&gt;One of the biggest new features&lt;/a&gt; is the usage of &lt;span class="Code"&gt;PackageReference&lt;/span&gt; to simply reference NuGet packages with a single entry. In contrast to the old way, all NuGet packages are typically downloaded to some default folder, usually &lt;span class="Code"&gt;%USERPROFILE%\.nuget\packages&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Recently, with the latest Visual Studio 2017 V15.9, the &lt;span class="Code"&gt;GeneratePathProperty&lt;/span&gt; was introduced. It allows you to define a build variable that holds the path to the NuGet package folder. It's useful if you want to access files in the NuGet package in your build steps. This could be, for example, running a CLI tool or, in my case, copying some files from the package to your output path.&lt;/p&gt;
&lt;p&gt;For example, &lt;a rel="noopener" href="https://github.com/xBimTeam" target="_blank" title="GitHub - xBim"&gt;the xBim toolkit&lt;/a&gt; is an Open Source collection of libraries that let you work with digital building models. Some of the more compute intensive operations are performed via a C++ dll that is loaded at runtime. For this, xBim requires the compiled dlls to be present in the output folder so it can find and load them.&lt;/p&gt;
&lt;p&gt;In my &lt;a rel="noopener" href="https://xbim-web.dangl.me/home" target="_blank" title="Georg Dangl - xBim Meets Angular"&gt;xbim-meets-angular demo&lt;/a&gt;, I have a small component that lets you upload IFC building model files, which are then tesselated and displayed right in the browser. For this, I want the C++ dlls to be copied to the build and publish output directories. I used to have a PowerShell build script do that, but now it's really simple to do with the project system itself:&lt;/p&gt;
&lt;p&gt;
&lt;script src="https://gist.github.com/GeorgDangl/28b82bfa91566a55ec6c2277312944bb.js"&gt;&lt;/script&gt;
&lt;/p&gt;
&lt;p&gt;Both libraries, for x86 and x64, are copied to the build and publish output in this snippet. No other code is required! You just need to set &lt;span class="Code"&gt;GeneratePathProperty="true"&lt;/span&gt; on the package reference, then the variable &lt;span class="Code"&gt;$(PkgXbim_Geometry)&lt;/span&gt; will point to the path of the package - including its version. Dots in the package name are simply replaced with underscores, so the variable for the package &lt;span class="Code"&gt;Xbim.Geometry&lt;/span&gt; becomes &lt;span class="Code"&gt;PkgXbim_Geometry&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;There's one small thing, though: Currently, it seems to work only for project types using the &lt;span class="Code"&gt;Microsoft.NET.Sdk.Web&lt;/span&gt; SDK, regular ones don't work yet. But &lt;a rel="noopener" href="https://github.com/dotnet/project-system/pull/4226" target="_blank" title="GitHub - dotnet project system - Issue 4226"&gt;support is just around the corner&lt;/a&gt;. In the meantime, you can simply use &lt;span class="Code"&gt;dotnet build&lt;/span&gt; instead of MSBuild if you're compiling for the classic .NET framework.&lt;/p&gt;
&lt;p&gt;Happy building!&lt;/p&gt;</description>
      <pubDate>Wed, 21 Nov 2018 16:52:50 Z</pubDate>
      <a10:updated>2018-11-21T16:52:50Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1371</guid>
      <link>https://blog.dangl.me/archive/integration-testing-in-memory-compiled-code-with-roslyn-visual-studio-2017-edition/</link>
      <category>DotNet</category>
      <category>Continuous Integration</category>
      <title>Integration Testing In Memory Compiled Code with Roslyn - Visual Studio 2017 Edition</title>
      <description>&lt;p&gt;Have you ever written code to generate code? &lt;em&gt;Probably&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Have you ever written proper integration tests for that? &lt;em&gt;Probably not&lt;/em&gt;.&lt;/p&gt;
&lt;blockquote&gt;This is a follow up post to &lt;a data-udi="umb://document/84cf1e72fc89438baafc4096c5beb264" href="/archive/integration-testing-in-memory-compiled-code-with-roslyn/" title="Integration Testing In Memory Compiled Code with Roslyn"&gt;last years article&lt;/a&gt;, which was still about the now deprecated &lt;span class="Code"&gt;project.json&lt;/span&gt; format&lt;/blockquote&gt;
&lt;p&gt;Everyone's done it - write code that writes code. Be it for converting from an esoteric Domain Specific Language, generating from a set of known data or for any other reason. It happens a lot, it's useful a lot, but it's not tested a lot. Testing such code has always been inconvenient, did involve a lot of disk IO and quite often relied on scripts and manual work. Luckily, with &lt;a rel="noopener noreferrer" href="https://github.com/dotnet/roslyn" target="_blank" title="GitHub - dotnet/roslyn"&gt;dotnets Roslyn compiler,&lt;/a&gt; there are NuGet packages for code analysis and compilation available that make all of this so easy!&lt;/p&gt;
&lt;p&gt;The &lt;a rel="noopener noreferrer" href="https://github.com/GeorgDangl/InMemoryCompilation" target="_blank" title="GitHub - GeorgDangl/InMemoryCompilation"&gt;complete sample repository is available at GitHub&lt;/a&gt;. Here are the interesting parts:&lt;/p&gt;
&lt;p&gt;
&lt;script src="https://gist.github.com/GeorgDangl/069a42d3dc1f5c2f9172d2e80e83170b.js?file=CodeGenerator.cs"&gt;&lt;/script&gt;
&lt;/p&gt;
&lt;p&gt;It starts with the &lt;span class="Code"&gt;CodeGenerator&lt;/span&gt;  which does what it's name implies - it creates code. In this case, it's a simple class that has one method: &lt;span class="Code"&gt;AddIntegers()&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;
&lt;script src="https://gist.github.com/GeorgDangl/069a42d3dc1f5c2f9172d2e80e83170b.js?file=InMemoreCompilation.Tests.csproj"&gt;&lt;/script&gt;
&lt;/p&gt;
&lt;p&gt;This &lt;span class="Code"&gt;InMemoreCompilation.Tests.csproj&lt;/span&gt; is a regular, xUnit enabled, project configuration file. There is a reference to the &lt;span&gt;&lt;span class="Code"&gt;Microsoft.CodeAnalysis.CSharp&lt;/span&gt; package. That one will bring the Roslyn API to your project.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;script src="https://gist.github.com/GeorgDangl/069a42d3dc1f5c2f9172d2e80e83170b.js?file=CodeGeneratorTests.cs"&gt;&lt;/script&gt;
&lt;/p&gt;
&lt;p&gt;The actual integration test class is quite big, so let's break it down into it's functional units: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class="Code"&gt;GenerateCode()&lt;/span&gt; does just that - it gets the string representation of the sourcecode&lt;/li&gt;
&lt;li&gt;&lt;span class="Code"&gt;CreateCompilation()&lt;/span&gt; takes the sourcecode, adds assembly references and turns it into a &lt;span class="pl-en"&gt;&lt;span class="Code"&gt;CSharpCompilation&lt;/span&gt; object&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="pl-en"&gt;&lt;span class="Code"&gt;CompileAndLoadAssembly()&lt;/span&gt; now invokes the Roslyn API to compile onto a MemoryStream, then loads it and makes the content available&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="pl-en"&gt;Finally, &lt;span class="Code"&gt;CallCalculatorMethod()&lt;/span&gt; uses reflection on the newly generated assembly and invokes the &lt;span class="Code"&gt;AddIntegers()&lt;/span&gt; method&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is a really interesting approach on tackling code generation. While I got the initial bits to set this up from &lt;a rel="noopener noreferrer" href="http://www.tugberkugurlu.com/archive/compiling-c-sharp-code-into-memory-and-executing-it-with-roslyn" target="_blank" title="Tugberk Ugurlu - Compiling C# Code Into Memory and Executing It with Roslyn"&gt;Tugberk Ugurlus&lt;/a&gt; blog, I've had &lt;a rel="noopener noreferrer" href="https://github.com/GeorgDangl/XmlTools" target="_blank" title="GitHub - GeorgDangl/XmlTools"&gt;a project of my own&lt;/a&gt; where I did some heavy code generation (for correcting Xml documents) where I needed that. There's also code that works both in .Net Core and the full .Net framework.&lt;/p&gt;
&lt;p&gt;Happy compiling!&lt;/p&gt;</description>
      <pubDate>Sat, 03 Feb 2018 16:12:43 Z</pubDate>
      <a10:updated>2018-02-03T16:12:43Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1367</guid>
      <link>https://blog.dangl.me/archive/xunit-tests-not-recognizing-target-framework-microsoftnetcoreapp-20/</link>
      <category>DotNet</category>
      <title>xUnit Tests Not Recognizing Target Framework Microsoft.NETCore.App 2.0</title>
      <description>&lt;p&gt;My preferred unit testing framework for .Net Core, &lt;a rel="noopener noreferrer" href="https://github.com/xunit/xunit" target="_blank" title="GitHub - xUnit"&gt;xUnit&lt;/a&gt;, has had quite a few changes for the 2.3 release. One of them was how the tests libraries themselves are executed and how the framework version was determined.&lt;/p&gt;
&lt;p&gt;This becomes a problem when you have multiple frameworks for version 2.0 installed, e.g. &lt;span class="Code"&gt;2.0.0&lt;/span&gt; and &lt;span class="Code"&gt;2.0.3&lt;/span&gt;. The compiler sets the version of .Net Core App to &lt;span class="Code"&gt;2.0&lt;/span&gt; when you target &lt;span class="Code"&gt;netcoreapp2.0&lt;/span&gt;, but then fails to resolve it to &lt;span class="Code"&gt;2.0.0&lt;/span&gt;. &lt;a rel="noopener noreferrer" href="https://github.com/dotnet/cli/issues/7901#issuecomment-345033407" target="_blank" title="GitHub - dotnet cli"&gt;livarcocc&lt;/a&gt; explains it here. You'll receive error messages like this when you attempt to run xUnit:&lt;/p&gt;
&lt;script src="https://gist.github.com/GeorgDangl/b37049f3534f990723adb4c21e31439c.js?file=errormessage.bat"&gt;&lt;/script&gt;
&lt;p&gt;This &lt;a rel="noopener noreferrer" href="https://github.com/xunit/xunit/issues/1573" target="_blank" title="GitHub - xUnit Issues"&gt;isn't a bug within xUnit&lt;/a&gt;, but rather with the dotnet CLI, but xUnit still has &lt;a rel="noopener noreferrer" href="https://github.com/xunit/xunit/issues/1577" target="_blank" title="GitHub - xUnit Issues"&gt;a patch for this planned&lt;/a&gt;. In the meantime, you can set the &lt;span class="Code"&gt;RuntimeFrameworkVersion&lt;/span&gt; attribute in your &lt;span class="Code"&gt;*.csproj&lt;/span&gt; file to a fixed version when running tests for &lt;span class="Code"&gt;netcoreapp2.0&lt;/span&gt;:&lt;/p&gt;
&lt;script src="https://gist.github.com/GeorgDangl/b37049f3534f990723adb4c21e31439c.js?file=testproject.csproj"&gt;&lt;/script&gt;
&lt;p&gt;Happy testing!&lt;/p&gt;</description>
      <pubDate>Thu, 30 Nov 2017 11:05:26 Z</pubDate>
      <a10:updated>2017-11-30T11:05:26Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1358</guid>
      <link>https://blog.dangl.me/archive/building-hacky-but-free-graphs-and-charts-in-xamarinforms-with-chartjs/</link>
      <category>DotNet</category>
      <title>Building Hacky but Free Graphs and Charts in Xamarin.Forms with Chart.js</title>
      <description>&lt;p&gt;Just recently, I bought a used Mac Mini to tip my toes into mobile development. After doing a bit of research, there's mostly three viable options for doing cross-platform mobile development: Either &lt;strong&gt;React Native&lt;/strong&gt;, &lt;strong&gt;Cordova&lt;/strong&gt; or &lt;strong&gt;Xamarin&lt;/strong&gt;. I figured that due to my knowledge in C#, Xamarin would be a nice fit. However, there's way less components and libraries than in the node eco system, which is especially true for charts. There are commercial options available, but I didn't find a free, open source charts library.&lt;/p&gt;
&lt;p&gt;But there's help: In Xamarin.Forms, you can easily use a &lt;span class="Code"&gt;WebView&lt;/span&gt; to display, well, web or Html content. It works surprisingly well, and you can even extend it to communicate between your .Net code and JavaScript in the Browser. So I tried it out and threw a bit of a proof-of-concept together:&lt;/p&gt;
&lt;script src="https://gist.github.com/GeorgDangl/4402f32b0dc0844f8d8c0f98fe072b7f.js?file=HackyReportPage.xaml"&gt;&lt;/script&gt;
&lt;p&gt;The Xaml for the page is quite simple. It's just a &lt;span class="Code"&gt;WebView&lt;/span&gt; that's bound to the &lt;span class="Code"&gt;ReportHtml&lt;/span&gt; property of the ViewModel.&lt;/p&gt;
&lt;p&gt;Then there's the ViewModel:&lt;/p&gt;
&lt;script src="https://gist.github.com/GeorgDangl/4402f32b0dc0844f8d8c0f98fe072b7f.js?file=HackyReportPageViewModel.cs"&gt;&lt;/script&gt;
&lt;p&gt;It's a bit long, since I've cramped everything in a single file. To summarize:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Build a valid Html document&lt;/li&gt;
&lt;li&gt;Include Chart.js&lt;/li&gt;
&lt;li&gt;Add your Chart.js configuration&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The sample requires some adjusting before you can use it. It's using &lt;a rel="noopener noreferrer" href="https://github.com/Fody/PropertyChanged" target="_blank" title="GitHub - Fody - PropertyChanged"&gt;PropertyChanged.Fody&lt;/a&gt; and Dan Siegels great &lt;a rel="noopener noreferrer" href="https://github.com/dansiegel/Prism-Templates" target="_blank" title="GitHub - dansiegel - Prism Template Pack"&gt;Prism Template Pack&lt;/a&gt;, so check these repos out if something isn't clear with the code.&lt;/p&gt;
&lt;p&gt;After that, you see this page:&lt;img id="__mcenew" style="display: block; margin-left: auto; margin-right: auto;" src="https://blog.dangl.me/media/1170/hacky_charts.jpg?width=351&amp;amp;height=625" alt="Chart.js rendered in a Xamarin WebView in the iOS simulator" width="351" height="625" data-udi="umb://media/301565202d374363b8437cf7ff202578" /&gt;&lt;/p&gt;
&lt;p&gt;Happy charting!&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</description>
      <pubDate>Tue, 31 Oct 2017 18:12:31 Z</pubDate>
      <a10:updated>2017-10-31T18:12:31Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1297</guid>
      <link>https://blog.dangl.me/archive/using-antlr4-msbuild-tasks-in-visual-studio-2017-and-with-the-dotnet-cli/</link>
      <category>DotNet</category>
      <title>Using ANTLR4 MSBuild Tasks in Visual Studio 2017 and with the Dotnet CLI</title>
      <description>&lt;p&gt;With the latest &lt;a rel="noopener noreferrer" href="https://github.com/tunnelvisionlabs/antlr4cs/releases/tag/v4.6.5-beta001" target="_blank" title="GitHub - ANTLR4 4.6.5-beta001 Release"&gt;4.6.5-beta001&lt;/a&gt; release of ANTLR4 for C#, it's finally easy again to work with ANTLR grammars in Visual Studio. Since the introduction of the &lt;span class="Code"&gt;project.json&lt;/span&gt; format, you had to write custom scripts to generate your lexers and parsers, cluttering your workspace with lots of generated code. Not anymore! It's now as simple as adding &lt;span class="Code"&gt;Antlr4&lt;/span&gt; items to your &lt;span class="Code"&gt;csproj&lt;/span&gt; file, point them to your grammar files and the MSBuild process takes care of it. Generated files are again stored in the &lt;span class="Code"&gt;obj/&lt;/span&gt; folder and don't mess with your project structure.&lt;/p&gt;
&lt;p&gt;Here's an example of the new build tasks:&lt;/p&gt;
&lt;script src="https://gist.github.com/GeorgDangl/2761c001fa99c1189ca8192a9324efaa.js"&gt;&lt;/script&gt;
&lt;p&gt;You can use the optional &lt;span&gt;&lt;span class="Code"&gt;PropertyGroup&lt;/span&gt; and set &lt;span class="Code"&gt;Antlr4UseCSharpGenerator&lt;/span&gt; to true to circumvent the Java tooling altogether and rely on the new, native C# code generation. This process works seamlessly both from within Visual Studio 2017 as well as the dotnet CLI. &lt;a rel="noopener noreferrer" href="https://github.com/GeorgDangl/Dangl.Calculator" target="_blank" title="GitHub - GeorgDangl - Dangl.Calculator"&gt;I've got a demo project for you to dive right in on GitHub&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;blockquote&gt;Remember, you only have to use the pre-release &lt;span class="Code"&gt;Antlr4.CodeGenerator&lt;/span&gt; as a build time dependency, the runtime can be kept at the latest stable version, not blocking you if you have to use stable versions or create packages of your own.&lt;/blockquote&gt;
&lt;p&gt;Happy parsing!&lt;/p&gt;</description>
      <pubDate>Fri, 11 Aug 2017 23:52:06 Z</pubDate>
      <a10:updated>2017-08-11T23:52:06Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1275</guid>
      <link>https://blog.dangl.me/archive/entityframeworkcore-sqlite-in-a-full-net-framework-xunit-class-library/</link>
      <category>DotNet</category>
      <title>EntityFrameworkCore.​Sqlite in a Full .Net Framework xUnit Class Library</title>
      <description>&lt;p&gt;While migrating a still project.json based project to Visual Studio 2017s *.csproj format, an integration tests project gave me a bit of a headache:&lt;/p&gt;
&lt;p&gt;It's been a class library project that used the &lt;a rel="noopener noreferrer" href="https://github.com/aspnet/Hosting/tree/dev/src/Microsoft.AspNetCore.TestHost" target="_blank" title="GitHub - Microsoft.AspNetCore.TestHost"&gt;Microsoft.AspNetCore.TestHost&lt;/a&gt; package for integration testing API calls. Since I wanted to make use of a relational database for data integrity and validation, I chose to use &lt;span class="Code"&gt;Microsoft.EntityFrameworkCore.Sqlite&lt;/span&gt; as database provider. After migration, however, I got a lot of &lt;span class="Code"&gt;System.DllNotFoundException&lt;/span&gt; telling me that &lt;span class="Code"&gt;sqlite3.dll&lt;/span&gt; could not be loaded.&lt;/p&gt;
&lt;p&gt;I have been unable to find any real cause for the issue, but it's got something to do with the SQLite NuGet package dlls not being copied to the output directory when targeting the full .Net Framework in a class library. Kinda, sorta, somehow. It comes up in issues where people couldn't run dotnet ef CLI commands without a startup project.&lt;/p&gt;
&lt;p&gt; Luckily, I could fix it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I made a &lt;span class="Code"&gt;copySQLiteDlls.ps1&lt;/span&gt; script that copied the required Dlls in a &lt;span class="Code"&gt;Dependencies&lt;/span&gt; folder in the solution root&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;script src="https://gist.github.com/GeorgDangl/6007c8d2a9e920c954485774a5fd016c.js?file=copySQLiteDlls.ps1"&gt;&lt;/script&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I added the Dlls to be included in the output on compilation in the &lt;span class="Code"&gt;*.csproj&lt;/span&gt; file:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;script src="https://gist.github.com/GeorgDangl/6007c8d2a9e920c954485774a5fd016c.js?file=project.csproj"&gt;&lt;/script&gt;
&lt;/p&gt;
&lt;p&gt;Just make sure to run the first script after a package restore or before running your tests and you should be fine. There should now be an &lt;span class="Code"&gt;x64&lt;/span&gt; and &lt;span class="Code"&gt;x86&lt;/span&gt; folder in your output directory containing the &lt;span class="Code"&gt;sqlite3.dll&lt;/span&gt; files.&lt;/p&gt;
&lt;p&gt;Happy integration!&lt;/p&gt;</description>
      <pubDate>Thu, 29 Jun 2017 10:15:36 Z</pubDate>
      <a10:updated>2017-06-29T10:15:36Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1253</guid>
      <link>https://blog.dangl.me/archive/integration-testing-in-memory-compiled-code-with-roslyn/</link>
      <category>DotNet</category>
      <category>Continuous Integration</category>
      <title>Integration Testing In Memory Compiled Code with Roslyn</title>
      <description>&lt;p&gt;Have you ever written code to generate code? &lt;em&gt;Probably&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Have you ever written proper integration tests for that? &lt;em&gt;Probably not&lt;/em&gt;.&lt;/p&gt;
&lt;blockquote&gt;There is now a &lt;a data-udi="umb://document/285ced6c2ffc498aacd5d15f5bf00c39" href="/archive/integration-testing-in-memory-compiled-code-with-roslyn-visual-studio-2017-edition/" title="Integration Testing In Memory Compiled Code with Roslyn - Visual Studio 2017 Edition"&gt;follow up article&lt;/a&gt; that uses the latest .Net project format in &lt;strong&gt;Visual Studio 2017&lt;/strong&gt;. This post is still displaying the now deprecated &lt;span class="Code"&gt;project.json&lt;/span&gt; configuration&lt;/blockquote&gt;
&lt;p&gt;Everyone's done it - write code that writes code. Be it for converting from an esoteric Domain Specific Language, generating from a set of known data or for any other reason. It happens a lot, it's useful a lot, but it's not tested a lot. Testing such code has always been inconvenient, did involve a lot of disk IO and quite often relied on scripts and manual work. Luckily, with &lt;a rel="noopener noreferrer" href="https://github.com/dotnet/roslyn" target="_blank" title="GitHub - dotnet/roslyn"&gt;dotnets Roslyn compiler,&lt;/a&gt; there are NuGet packages for code analysis and compilation available that make all of this so easy!&lt;/p&gt;
&lt;p&gt;The &lt;a rel="noopener noreferrer" href="https://github.com/GeorgDangl/InMemoryCompilation" target="_blank" title="GitHub - GeorgDangl/InMemoryCompilation"&gt;complete sample repository is available at GitHub&lt;/a&gt;. Here are the interesting parts:&lt;/p&gt;
&lt;p&gt;
&lt;script src="https://gist.github.com/GeorgDangl/4a9982a3b520f056a9e890635b3695e0.js?file=CodeGenerator.cs"&gt;&lt;/script&gt;
&lt;/p&gt;
&lt;p&gt;It starts with the &lt;span class="Code"&gt;CodeGenerator&lt;/span&gt;  which does what it's name implies - it creates code. In this case, it's a simple class that has one method: &lt;span class="Code"&gt;AddIntegers()&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;
&lt;script src="https://gist.github.com/GeorgDangl/4a9982a3b520f056a9e890635b3695e0.js?file=project.json"&gt;&lt;/script&gt;
&lt;/p&gt;
&lt;p&gt;This &lt;span class="Code"&gt;project.json&lt;/span&gt; is a regular, xUnit enabled, configuration file. There is a reference to the &lt;span&gt;&lt;span class="Code"&gt;Microsoft.CodeAnalysis.CSharp&lt;/span&gt; package. That one will bring the Roslyn API to your project.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;script src="https://gist.github.com/GeorgDangl/4a9982a3b520f056a9e890635b3695e0.js?file=CodeGeneratorTests.cs"&gt;&lt;/script&gt;
&lt;/p&gt;
&lt;p&gt;The actual integration test class is quite big, so let's break it down into it's functional units: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class="Code"&gt;GenerateCode()&lt;/span&gt; does just that - it gets the string representation of the sourcecode&lt;/li&gt;
&lt;li&gt;&lt;span class="Code"&gt;CreateCompilation()&lt;/span&gt; takes the sourcecode, adds assembly references and turns it into a &lt;span class="pl-en"&gt;&lt;span class="Code"&gt;CSharpCompilation&lt;/span&gt; object&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="pl-en"&gt;&lt;span class="Code"&gt;CompileAndLoadAssembly()&lt;/span&gt; now invokes the Roslyn API to compile onto a MemoryStream, then loads it and makes the content available&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="pl-en"&gt;Finally, &lt;span class="Code"&gt;CallCalculatorMethod()&lt;/span&gt; uses reflection on the newly generated assembly and invokes the &lt;span class="Code"&gt;AddIntegers()&lt;/span&gt; method&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is a really interesting approach on tackling code generation. While I got the initial bits to set this up from &lt;a rel="noopener noreferrer" href="http://www.tugberkugurlu.com/archive/compiling-c-sharp-code-into-memory-and-executing-it-with-roslyn" target="_blank" title="Tugberk Ugurlu - Compiling C# Code Into Memory and Executing It with Roslyn"&gt;Tugberk Ugurlus&lt;/a&gt; blog, I've had &lt;a rel="noopener noreferrer" href="https://github.com/GeorgDangl/XmlTools" target="_blank" title="GitHub - GeorgDangl/XmlTools"&gt;a project of my own&lt;/a&gt; where I did some heavy code generation (for correcting Xml documents) where I needed that. There's also code that works both in .Net Core and the full .Net framework.&lt;/p&gt;
&lt;p&gt;Happy compiling!&lt;/p&gt;</description>
      <pubDate>Fri, 07 Apr 2017 19:20:49 Z</pubDate>
      <a10:updated>2017-04-07T19:20:49Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1238</guid>
      <link>https://blog.dangl.me/archive/using-xbim-geometry-conversion-in-the-new-aspnet-project-format/</link>
      <category>DotNet</category>
      <title>Using xBim Geometry Conversion in the New Asp.Net Project Format</title>
      <description>&lt;p&gt;Recently at work, we were evaluating a few options to render building models in the browser. Building Information Modeling (BIM) in interoperability scenarios is done via &lt;a href="https://en.wikipedia.org/wiki/Industry_Foundation_Classes" target="_blank" title="Wikipedia Industry Foundation Classes"&gt;Industry Foundation Classes&lt;/a&gt;, mostly in the STEP Physical File format. The schema is quite huge and complex with all the things you have to consider, so we were glad to find the &lt;a href="https://github.com/xBimTeam" target="_blank" title="GitHub xBim Team"&gt;xBim&lt;/a&gt; open source project on GitHub. They've got both projects to visualize building models in the browser with WebGL as well as conversion tools to create the binary-formatted geometry mesh. To achieve that, native C++ libraries are dynamically loaded (so no .Net Core compatibility) which must be present in the bin folder. The C++ libraries are expected either in the same folder as the application binaries or in a &lt;span class="Code"&gt;x64&lt;/span&gt; (or &lt;span class="Code"&gt;x86&lt;/span&gt;, respectively) sub folder (See &lt;a href="https://github.com/xBimTeam/XbimGeometry/blob/master/Xbim.Geometry.Engine.Interop/XbimCustomAssemblyResolver.cs" target="_blank" title="XbimCustomAssemblyResolver.cs on GitHub"&gt;here&lt;/a&gt; for more details). In regular projects, the &lt;span class="Code"&gt;xBim.Geometry&lt;/span&gt; NuGet package adds a build task to copy the dlls into the build output folder, but this doesn't work with the new tooling. You can, however, get it to work in Visual Studio 2015 by taking care of supplying the interop dlls yourself.&lt;/p&gt;
&lt;p&gt;Add a PowerShell file to the root of your project that takes care of copying the C++ dlls from the &lt;span&gt;NuGet &lt;/span&gt;package cache to your project:&lt;/p&gt;
&lt;script src="https://gist.github.com/GeorgDangl/d694a2d86593d989eb6474d4e64cb6fc.js?file=copyGeometryInteropDlls.ps1"&gt;&lt;/script&gt;
&lt;p&gt;Now you need to define three things in the &lt;span class="Code"&gt;project.json&lt;/span&gt; file:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A &lt;span class="Code"&gt;precompile&lt;/span&gt; command that invokes the above PowerShell script before each build. That comes with the side effect of breaking incremental build, but &lt;a href="https://github.com/dotnet/cli/issues/3436" target="_blank" title="GitHub dotnet/cli Pre/Post restore script does not run"&gt;there's no way around that currently&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;span class="Code"&gt;buildOptions:copyToOutput:mappings&lt;/span&gt; entry to copy the interop dlls to the build output folder&lt;/li&gt;
&lt;li&gt;&lt;span class="Code"&gt;publishOptions:mappings&lt;/span&gt; to copy the interop dlls to the publish output folder (and I have no idea why this doesn't already take the &lt;span class="Code"&gt;buildOptions&lt;/span&gt; into account, but that's the way it is I guess)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here's a (shortened) &lt;span class="Code"&gt;project.json&lt;/span&gt; file with the configuration:&lt;/p&gt;
&lt;script src="https://gist.github.com/GeorgDangl/d694a2d86593d989eb6474d4e64cb6fc.js?file=project.json"&gt;&lt;/script&gt;
&lt;p&gt;I've created a small &lt;a href="https://xbim-web.dangl.me/" target="_blank" title="xBimMeetsAngular"&gt;sample web app&lt;/a&gt; that's also available &lt;a href="https://github.com/GeorgDangl/xbim-meets-angular" target="_blank" title="GitHub - GeorgDangl - xbim-meets-angular"&gt;on GitHub&lt;/a&gt;. This app already makes use of Angular 2 and the TypeScript version of xBimWebUI which isn't yet merged in the original repository, so you should take a look at &lt;a href="https://github.com/GeorgDangl/XbimWebUI" target="_blank" title="GitHub - Georg Dangl - XbimWebUI fork"&gt;my fork&lt;/a&gt; until it's accepted.&lt;/p&gt;
&lt;p&gt;&lt;img id="__mcenew" style="display: block; margin-left: auto; margin-right: auto;" src="https://blog.dangl.me/media/1108/xbimwebglexample.png" alt="Building Model rendered with WebGL in the Browser (with xBim)" data-id="1240"&gt;&lt;/p&gt;
&lt;p&gt;Happy meshing!&lt;/p&gt;</description>
      <pubDate>Thu, 02 Feb 2017 16:38:19 Z</pubDate>
      <a10:updated>2017-02-02T16:38:19Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1218</guid>
      <link>https://blog.dangl.me/archive/running-xunit-tests-for-multiple-frameworks/</link>
      <category>DotNet</category>
      <title>Running xUnit Tests for Multiple Frameworks</title>
      <description>&lt;p&gt;Say you're building some class library with the intent to be used in multiple frameworks, like .Net Core and .Net (Full). Since NETStandard still hasn't really gotten off yet (and I think you should be &lt;a href="https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/" target="_blank" title="MSDN - .NET Blog - Introducing .NET Standard"&gt;waiting for 2.0&lt;/a&gt; before you can use it as sole target), you may want to have your tests run for every supported framework.&lt;/p&gt;
&lt;p&gt;With xUnit, that's actually quite easy! Just have your test projects &lt;span class="Code"&gt;project.json&lt;/span&gt; file target multiple frameworks like in the example below:&lt;/p&gt;
&lt;pre class="brush: javascript;"&gt;{
  "dependencies": {
    "xunit": "2.2.0-beta2-build3300",
    "dotnet-test-xunit": "2.2.0-preview2-build1029",
  },
  "testRunner": "xunit",
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.0.1",
          "type": "platform"
        }
      }
    },
    "net461": {}
  }
}&lt;/pre&gt;
&lt;p&gt;Then run &lt;span class="Code"&gt;dotnet test&lt;/span&gt; and you'll see that both framework targets are being compiled and run:&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;dotnet test

Compiling Dangl.Calculator for .NETStandard,Version=v1.4
...
Compiling Dangl.Calculator.Tests for .NETCoreApp,Version=v1.0
...
=== TEST EXECUTION SUMMARY ===
   Dangl.Calculator.Tests  Total: 168, Errors: 0, Failed: 0, Skipped: 0, Time: 0,521s
...
Compiling Dangl.Calculator.Tests for .NETFramework,Version=v4.6.1
...
=== TEST EXECUTION SUMMARY ===
   Dangl.Calculator.Tests  Total: 168, Errors: 0, Failed: 0, Skipped: 0, Time: 0,324s
SUMMARY: Total: 2 targets, Passed: 2, Failed: 0.&lt;/pre&gt;
&lt;p&gt;The dotnet test runner takes care of compiling the project both for &lt;span&gt;&lt;span class="Code"&gt;.NETCoreApp,Version=v1.0&lt;/span&gt; and &lt;span class="Code"&gt;.NETFramework,Version=v4.6.1&lt;/span&gt; and runs the test suite for each. It also works with &lt;a data-id="1172" href="/archive/unit-testing-and-code-coverage-with-jenkins-and-net-core/" target="_blank" title="Unit Testing and Code Coverage with Jenkins and .NET Core"&gt;code coverage&lt;/a&gt;, so branches from conditional compilation are covered as well.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Happy Testing=)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</description>
      <pubDate>Wed, 28 Sep 2016 22:27:18 Z</pubDate>
      <a10:updated>2016-09-28T22:27:18Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1216</guid>
      <link>https://blog.dangl.me/archive/missing-encoding-in-net-core-apps/</link>
      <category>DotNet</category>
      <title>Missing Encoding in .Net Core Apps</title>
      <description>&lt;p&gt;So, today, while migrating a project to .Net Core, I've encountered a failing unit test that told me this:&lt;/p&gt;
&lt;p&gt;&lt;img id="__mcenew" src="https://blog.dangl.me/media/1095/unittesterror.png" alt="Missing Encoding Unit Test Error in .Net Core" data-id="1215"&gt;&lt;/p&gt;
&lt;p&gt;Code page 1252 ist the Western European standard code page, but I was obviously missing it. That's where I found &lt;a href="http://stackoverflow.com/questions/37870084/net-core-doesnt-know-about-windows-1252-how-to-fix#answer-37870346" target="_blank" title="StackOvervlow - How to execute different actions based on the framework? (ASP.NET 5)"&gt;svicks post on StackOverflow&lt;/a&gt;, which basically explained what went wrong:&lt;/p&gt;
&lt;p&gt;In .Net Core, available encodings need to be registered before you can access them.&lt;/p&gt;
&lt;p&gt;First, you need to import the &lt;span class="Code"&gt;System.Text.Encoding.CodePages&lt;/span&gt;​ dependency and define a compilation value (I chose &lt;span class="Code"&gt;NETCORE&lt;/span&gt;) in your &lt;span class="Code"&gt;project.json&lt;/span&gt;:&lt;/p&gt;
&lt;pre class="brush: javascript;"&gt;"frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dnxcore50",
        "portable-net45+win8"
      ],
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.0.1",
          "type": "platform"
        },
        "System.Text.Encoding.CodePages": "4.0.1"
      },
      "buildOptions": {
        "define": [ "NETCORE" ]
      }
    },
    "net461": {}
  }&lt;/pre&gt;
&lt;p&gt;Next, register the provider from within your code via conditional compilation:&lt;/p&gt;
&lt;pre class="brush: c-sharp;"&gt;#if NETCORE
                    Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
#endif&lt;/pre&gt;
&lt;p&gt;Happy Encoding=)&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</description>
      <pubDate>Mon, 26 Sep 2016 21:23:54 Z</pubDate>
      <a10:updated>2016-09-26T21:23:54Z</a10:updated>
    </item>
  </channel>
</rss>