Skip to content

Instantly share code, notes, and snippets.

View KirillOsenkov's full-sized avatar

Kirill Osenkov KirillOsenkov

View GitHub Profile
@jbevain
jbevain / Image.cs
Created December 8, 2009 16:38
A class to test whether a file is a PE file and a managed assembly
//
// Image.cs
//
// Author:
// Jb Evain ([email protected])
//
// WARNING: code now lives in http://github.com/jbevain/mono.reflection
//
// (C) 2009 Novell, Inc. (http://www.novell.com)
//
@brianlow
brianlow / FindConflictingReferences.cs
Created January 3, 2012 03:04
Find conflicting assembly references
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using NUnit.Framework;
namespace MyProject
{
[TestFixture]
@trusktr
trusktr / DefaultKeyBinding.dict
Last active November 12, 2024 19:14
My DefaultKeyBinding.dict for Mac OS X
/* ~/Library/KeyBindings/DefaultKeyBinding.Dict
This file remaps the key bindings of a single user on Mac OS X 10.5 to more
closely match default behavior on Windows systems. This makes the Command key
behave like Windows Control key. To use Control instead of Command, either swap
Control and Command in Apple->System Preferences->Keyboard->Modifier Keys...
or replace @ with ^ in this file.
Here is a rough cheatsheet for syntax.
Key Modifiers
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello, CoreCLR!");
}
}
@sayedihashimi
sayedihashimi / nopreorpostevents.targets
Created April 16, 2015 09:47
This file will disable pre and post build events globally in MSBuild and Visual Studio
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
You can use this file to disable pre and post events globally across both MSBuild and Visual Studio.
To use this file, you have two options.
1. Save this file as C:\Program Files (x86)\MSBuild\v14.0\Custom.After.Microsoft.Common.targets
Or whatever the value of the MSBuild property $(CustomAfterMicrosoftCommonTargets).
2. Save this file to a random location, lets say C:\temp\msbuild\nopreorpostevents.targets,
then set the CustomAfterMicrosoftCommonTargets env var to point to that file. Then start Visual Studio.
@davkean
davkean / AssemblyLoadFile.md
Last active June 2, 2017 22:36
Why Assembly.LoadFile is not the right API to call

Assembly.LoadFile is almost always the wrong API to call inside an application. It says to the CLR “hands off, this assembly will live in its own little universe and don’t you apply any of your normal rules for loading assemblies”. Below you’ve effectively loaded two of these universes and one doesn’t see the other. LoadFile also forces you to hook onto AssemblyResolve (like you’ve done below[1]) and tell the CLR about every dependency that assembly needs to resolve. It also opts you out of other things such as binding redirects, retargeting (v1 portable won’t load below) and a few other things.

Assembly.LoadFile is used by designers, and should be called Assembly.LoadFile_ForDesignerUseOnly, it’s unfortunate it has such as tempting name.

If this is inside of VS, it is most definitely not the correct API to call. You want to use Assembly.Load, Assembly.LoadFrom and/or use VS related APIs for registering binding paths. It already has an assembly resolve, and no one else should be hooking onto it.

[1] That

String interpolation

var x = 1;

// same as string.Format("A {0} B", x) 
var y1 = $"A {x} B"; // y == "A 1 B"

// $@ for multiline
var y2 = $@"A
@KirillOsenkov
KirillOsenkov / AssemblyLoadFile.md
Created June 2, 2017 22:36 — forked from davkean/AssemblyLoadFile.md
Why Assembly.LoadFile is not the right API to call

Assembly.LoadFile is almost always the wrong API to call inside an application. It says to the CLR “hands off, this assembly will live in its own little universe and don’t you apply any of your normal rules for loading assemblies”. Below you’ve effectively loaded two of these universes and one doesn’t see the other. LoadFile also forces you to hook onto AssemblyResolve (like you’ve done below[1]) and tell the CLR about every dependency that assembly needs to resolve. It also opts you out of other things such as binding redirects, retargeting (v1 portable won’t load below) and a few other things.

Assembly.LoadFile is used by designers, and should be called Assembly.LoadFile_ForDesignerUseOnly, it’s unfortunate it has such as tempting name.

If this is inside of VS, it is most definitely not the correct API to call. You want to use Assembly.Load, Assembly.LoadFrom and/or use VS related APIs for registering binding paths. It already has an assembly resolve, and no one else should be hooking onto it.

[1] That

@DustinCampbell
DustinCampbell / using-msbuildworkspace.md
Created April 10, 2018 21:36
Using MSBuildWorkspace

Introduction

Roslyn provides a rich set of APIs for analyzing C# and Visual Basic source code, but constructing a context in which to perform analysis can be challenging. For simple tasks, creating a Compilation populated with SyntaxTrees, MetadataReferences and a handful of options may suffice. However, if there are multiple projects involved in the analysis, it is more complicated because multiple Compilations need to be created with references between them.

To simplify the construction process. Roslyn provides the Workspace API, which can be used to model solutions, projects and documents. The Workspace API performs all of the heavy lifting needed to parse SyntaxTrees from source code, load MetadataReferences, and construct Compilations and add references between them.

@jeffkl
jeffkl / Improvements to MSBuild 15.md
Last active November 17, 2022 23:45
Improvements to MSBuild 15

Improvements to MSBuild 15

In MSBuild 15, we've been hard at work adding features that make it easier to manage your build. The development world has evolved greatly in the last 10 years with NuGet packages, more platforms, and the internet in general. We wanted to modernize some of MSBuild to propel it forward to a new era.

Open Source

MSBuild 15 is open source for the first time. This has allowed us to work in the open in a tighter loop with our customers. It also has allowed community contribution so that features of MSBuild can be provided that the core MSBuild development team does not have time to implement.