Skip to content

Instantly share code, notes, and snippets.

View KirillOsenkov's full-sized avatar

Kirill Osenkov KirillOsenkov

View GitHub Profile
@KirillOsenkov
KirillOsenkov / copy.proj
Last active October 25, 2017 17:48
Override MSBuild Copy task
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<Copy SourceFiles="copy.proj" DestinationFiles="destination.proj" />
</Target>
<UsingTask TaskName="Copy" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<SourceFiles Required="true" ParameterType="Microsoft.Build.Framework.ITaskItem[]" />
<DestinationFolder ParameterType="Microsoft.Build.Framework.ITaskItem" />
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace EnumPrimes
{
public struct Rational
{
using System.IO;
using System.Linq;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
// <?xml version="1.0" encoding="utf-8"?>
// <packages>
// <package id="iTextSharp" version="5.5.9" targetFramework="net452" />
// <package id="PDFsharp" version="1.32.3057.0" targetFramework="net452" />
// </packages>
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main(string[] args)
{
foreach (var item in GetSequence().Take(50))
{
using System.Collections.Concurrent;
using System.Diagnostics.Contracts;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.Win32
{
/// <summary>
/// See http://msdn.microsoft.com/en-us/library/cc231196.aspx for details.
using System.IO;
using System.Linq;
class FileRangeRenamer
{
static void Main(string[] args)
{
var folder = @"D:\Photos\June12\Clouds1";
var files = Directory.GetFiles(folder, "*.CR2").OrderBy(f => f).ToArray();
foreach (var file in files)
@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

@KirillOsenkov
KirillOsenkov / Directory.Build.props
Created April 12, 2019 16:56
SDK-style Directory.Build.props for common output directory
<Project>
<PropertyGroup>
<SrcRoot>$(MSBuildThisFileDirectory)</SrcRoot>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(SrcRoot)\</SolutionDir>
<Configuration Condition="$(Configuration) == ''">Debug</Configuration>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
@KirillOsenkov
KirillOsenkov / RoslynToMonoDevelopIVT.txt
Created April 12, 2019 20:57
IVT usage from Roslyn to MonoDevelop
C:\xmd\main\build\bin\Microsoft.CodeAnalysis.dll
================================================
Consumed in: C:\xmd\main\build\bin\MonoDevelop.Ide.dll
Microsoft.CodeAnalysis.Text.TextLineCollection Microsoft.CodeAnalysis.Text.SourceText::GetLinesCore()
System.Void Microsoft.CodeAnalysis.Diagnostics.AnalyzerReference::.ctor()
System.Void Microsoft.CodeAnalysis.DocumentationProvider::.ctor()
System.Void Microsoft.CodeAnalysis.PortableExecutableReference::.ctor(Microsoft.CodeAnalysis.MetadataReferenceProperties,System.String,Microsoft.CodeAnalysis.DocumentationProvider)
System.Void Microsoft.CodeAnalysis.Text.SourceText::.ctor(System.Collections.Immutable.ImmutableArray`1<System.Byte>,Microsoft.CodeAnalysis.Text.SourceHashAlgorithm,Microsoft.CodeAnalysis.Text.SourceTextContainer)
System.Void Microsoft.CodeAnalysis.Text.TextLineCollection::.ctor()
@KirillOsenkov
KirillOsenkov / AddGeneratedFile.csproj
Last active April 17, 2025 05:12
Sample of generating a .cs file during build and adding it to the compilation
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<GeneratedText><![CDATA[
using System%3B