Skip to content

Instantly share code, notes, and snippets.

View AArnott's full-sized avatar

Andrew Arnott AArnott

View GitHub Profile
@benvillalobos
benvillalobos / hooking-into-seplatform-negotiation.md
Created July 18, 2022 19:59
Hooking Into SetPlatform Negotiation

Say you want to modify each project reference once you know what platforms it can build as, the only place to do it (before PlatformNegotiation kicks in) is...

BeforeTargets=_GetProjectReferencePlatformProperties AfterTargets=_GetProjectReferenceTargetFrameworkProperties

_GetProjectReferenceTargetFrameworkProperties is the target that calls MSBuild on a project reference to gather its information (and see what it would build as). Only AFTER this target you can mess with ProjectReferences while understanding what they can build as.

If you target runs between the two above, you should have an _MSBuildProjectReferenceExistent item you can mess around with.

@paranlee
paranlee / Ubuntu disk resize Hyper-V Quick.md
Last active February 17, 2024 20:28
Ubuntu disk resize Hyper-V Quick.

Expand Ubuntu disk after Hyper-V Quick Create

It is quick and easy to use Hyper-V Quick Create to get an Ubuntu virtual machine running on a Windows 10 computer. However, if this method is used, you may end up with a tiny Ubuntu virtual disk that will not be useful for any serious work and it is less obvious than the initial setup how to increase the size of this disk.

These steps fix the problem:

1. Turn off the VM.

2. Hyper-V Manager Settings Virtual hard disk.

@AlexVallat
AlexVallat / msbuild-itemgroup-intersection.md
Created March 4, 2021 18:20
MSBuild ItemGroup Intersection

It's not obvious how to produce an intersection of two itemgroups in MSBuild. There's this brainteaser solution based on tricky metadata behaviour, but it only works inside a <target> due to it's use of metadata.

There is another way. Algebra tells us that A ∩ B = A ∖ (A∖B): intersection of A and B is A excluding (A excluding B). This can be expressed in MSBuild as:

<ItemGroup>
	<A Include="1" />
	<A Include="2" />
	<A Include="3" />
@jiripolasek
jiripolasek / ReflectionExtensions.cs
Last active November 23, 2020 04:45
Detect init-only property using reflection
public static class ReflectionExtensions
{
/// <summary>
/// Gets a value indicating whether property has init accessor declared.
/// </summary>
/// <param name="propertyInfo"></param>
/// <returns>Returns <c>true</c> if the property is declared as init-only; otherwise returns <c>false</c>.</returns>
public static bool IsInitOnly(this PropertyInfo propertyInfo)
{
if (propertyInfo == null)
@trippwill
trippwill / Microsoft.PowerShell_profile.ps1
Created December 9, 2019 16:57
PowerShell Core Profile
### Customize Prompt for Visual Studio Developer PowerShell
# Get the current prompt
$defaultPrompt = (Get-Item function:prompt).ScriptBlock
# Setup the custom prompt
function prompt {
$pr = if (Test-Path env:/VSINSTALLDIR) { "[VS $env:VisualStudioVersion]:" }
else {''}
Write-Host $pr -NoNewline -ForegroundColor DarkMagenta
@joyrexus
joyrexus / README.md
Last active February 24, 2024 15:16
collapsible markdown

collapsible markdown?

CLICK ME

yes, even hidden code blocks!

print("hello world!")
@kzu
kzu / vsmef.linq
Created July 8, 2016 15:58
VSMEF Components
var xmlns = new XmlNamespaceManager(new NameTable());
xmlns.AddNamespace("vsx10", "http://schemas.microsoft.com/developer/vsx-schema/2010");
xmlns.AddNamespace("vsx11", "http://schemas.microsoft.com/developer/vsx-schema/2011");
var vsix = from file in Directory.EnumerateFiles(@"C:\Program Files (x86)\Microsoft Visual Studio 14.0", "extension.vsixmanifest", SearchOption.AllDirectories)
where File.ReadAllLines(file)[0].StartsWith("<")
select file;
var mef = vsix
.Select(x => XDocument.Load(x))
@vbfox
vbfox / ExtractNestedClassesToSeparateFiles.fs
Last active November 3, 2015 00:00
Extract nested classes/struct/enums to their own files
open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.CSharp
open Microsoft.CodeAnalysis.CSharp.Syntax
open Microsoft.CodeAnalysis.MSBuild
open Microsoft.CodeAnalysis.Formatting
open System.IO
module FluentRoslynLite =
let (!!) t = Async.AwaitTask t
let emptyFile = SyntaxFactory.CompilationUnit()
@geraintluff
geraintluff / base64-web-safe.js
Created October 9, 2015 15:36
Convert base64 to and from web-safe variant
// Convert from normal to web-safe, strip trailing "="s
function webSafe64(base64) {
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
}
// Convert from web-safe to normal, add trailing "="s
function normal64(base64) {
return base64.replace(/\-/g, '+').replace(/_/g, '/') + '=='.substring(0, (3*base64.length)%4);
}
@nguerrera
nguerrera / DelegateToStaticWithFirstArg.cs
Last active August 29, 2015 14:05
Creating a delegate bound to a static method with first argument in verifiable IL
// And this program can be writen in C# after all if you use an extension method!
// (And the codegen is exactly as the optimal hand-written IL below.)
//
// Thanks to Vladimir Sadov on the compiler team for teaching me about it!
static class Program
{
static void Main()
{
var f = new Func<string>("World".StaticMethod);