Skip to content

Instantly share code, notes, and snippets.

@duncansmart
duncansmart / NET47ValueTupleFix.props
Created May 30, 2017 15:05
Fix for `CS8179: Predefined type 'System.ValueTuple`2' is not defined or imported` in Razor files
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
Copy to %LOCALAPPDATA%\Microsoft\MSBuild\15.0\Microsoft.Common.targets\ImportAfter\
-->
<PropertyGroup>
<!-- If we have .NET 4.7 use ValueTuple defined in mscorlib -->
<DotNet47Installed Condition=" '$([MSBuild]::GetRegistryValueFromView(`HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.7`, null, `NOT_FOUND`, RegistryView.Registry64))' == '' ">True</DotNet47Installed>
<TargetFrameworkVersion Condition="$(TargetFrameworkVersion) == '4.6' And '$(DotNet47Installed)' == 'True'">v4.7</TargetFrameworkVersion>
</PropertyGroup>
@duncansmart
duncansmart / Windows 10 CU ValueTuple hack.md
Last active April 24, 2017 10:23
Windows 10 CU ValueTuple hack

Define an environment variable called Windows10CUFix with value = 1

In proj file locate <Reference Include="System.ValueTuple... and replace with following:

<Reference Condition=" '$(Windows10CUFix)' == '' " Include="System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
    <HintPath>..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Condition=" '$(Windows10CUFix)' != '' " Include="mscorlib">
    <HintPath>$(WINDIR)\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll</HintPath>
@duncansmart
duncansmart / StreamingXmlParser.cs
Created October 11, 2016 14:24
Streaming XML parser
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Diagnostics;
class StreamingXmlParser
{
public class ElementInfo
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using FakeItEasy;
using MimeKit;
using System.Collections.Specialized;
using System.Collections.Generic;
@duncansmart
duncansmart / env.aspx
Created April 12, 2016 17:59
Dump server environment variables
<%@ Page Language="C#" %>
<ul>
<% foreach (DictionaryEntry item in Environment.GetEnvironmentVariables()) { %>
<li><%:item.Key%>: <code><%:item.Value%></code></li>
<%}%>
<ul>
:: tracks all branches for a remote e.g. `git branch --track origin/foo foo`
:: based on info from http://stackoverflow.com/questions/67699/clone-all-remote-branches-with-git
git branch -r | for /f "delims=/ tokens=1,*" %%A IN ('find "origin/"') do (
@git branch --track %%A/%%B %%B
)
@duncansmart
duncansmart / PrecompileWebApp.cs
Created January 21, 2016 10:33
How to ensure a an ASP.NET web app is fully compiled at startup
using System;
using System.Web;
// ...
namespace Foo
{
public class MyWebApp : System.Web.HttpApplication
{
protected void Application_Start()
{
var cbm = new System.Web.Compilation.ClientBuildManager(HttpRuntime.AppDomainAppId, null);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Collections.Concurrent;
using System.Reflection;
static class ReflectionUtil
{
static ConcurrentDictionary<PropertyInfo, Func<object, object>> _propertyGettersCache = new ConcurrentDictionary<PropertyInfo, Func<object, object>>();
@duncansmart
duncansmart / icloud-reminders-as-text.js
Created April 23, 2015 10:59
Get iCloud Reminders as text
[].map.call(document.querySelectorAll('iframe[name=reminders]')[0].contentDocument.querySelectorAll('.reminder-not-completed-view .reminder-row .reminder-title'), function(el) {
return el.textContent;
}).join('\r\n');
@duncansmart
duncansmart / DotNetZipOneFile.cs
Last active August 29, 2015 14:11
Creates a single source file version of DotNetZip
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace ZipReducedOneFile
{
class Program
{
static void Main()