Skip to content

Latest commit

 

History

History
188 lines (158 loc) · 7.41 KB

DEVELOPING.md

File metadata and controls

188 lines (158 loc) · 7.41 KB

Content

Building

Required:

If your build fails because some packages are not available, let say F#, then just disable these project and hope for nuget server to work later on ;)

Debugging

There are two debug profiles available in VS drop down

Running Tests

  • To run "Classic" tests build the solution and run runClassicTests.cmd in the root directory or comment out the netcoreapp1.0 part of all project.json files that belong to the testing projects.
  • To run "Core" tests you just need to open Test Explorer in Visual Studio and rebuild the solution. Then tests show up in Test Explorer and you can simply run them.

Remember to do both before pulling a PR or publishing new version

Development

Branches

Please, use the develop branch for developing. The master branch should correspond the latest NuGet package of the library.

New project files

.csproj and package.config files have been replaced with .xproj and project.json files. project.json automatically references all .cs files so you don’t have to update it with every new class/interface/enum added (number of git conflicts has just dropped). It also has some side efects. For example if you create some subfolder in any of the folders that contain project.json file and put some .cs files there, then these files are going to be compiled as part of parent project by default.

The other side effect is that xproj displays all files by default: xproj displays all files by default

But if you want to include some files as resources, you have to do this in explicit way:

"buildOptions": {
    "embed": [ "Templates/*.txt", "Templates/*.R", "Templates/*.json" ]
}

Project.json allows us to target multiple frameworks with one file and manage all dependencies in single place. Simplicity over complexity!

 "frameworks": {
    "net40": {
      "compilationOptions": {
        "define": [ "CLASSIC" ]
      },
      "frameworkAssemblies": {
        "Microsoft.Build": "4.0.0.0",
        "Microsoft.Build.Framework": "4.0.0.0",
        "Microsoft.Build.Utilities.v4.0": "4.0.0.0",
        "System.Management": "4.0.0.0"
      }
    },
    "netstandard1.5": {
      "buildOptions": {
        "define": [ "CORE", "RC2" ]
      },
      "dependencies": {
        "System.Linq": "4.1.0-rc2-24027",
        "System.Resources.ResourceManager": "4.0.1-rc2-24027",
        "Microsoft.CSharp": "4.0.1-rc2-24027",
        "Microsoft.Win32.Primitives": "4.0.1-rc2-24027",
        "System.Console": "4.0.0-rc2-24027",
        "System.Text.RegularExpressions": "4.0.12-rc2-24027",
        "System.Threading": "4.0.11-rc2-24027",
        "System.Reflection": "4.1.0-rc2-24027",
        "System.Reflection.Primitives": "4.0.1-rc2-24027",
        "System.Reflection.TypeExtensions": "4.1.0-rc2-24027",
        "System.Threading.Thread": "4.0.0-rc2-24027",
        "System.Diagnostics.Process": "4.1.0-rc2-24027",
        "System.IO.FileSystem": "4.0.1-rc2-24027",
        "System.Runtime.InteropServices.RuntimeInformation": "4.0.0-rc2-24027",
        "System.Runtime.Serialization.Primitives": "4.1.1-rc2-24027",
        "System.Diagnostics.Tools": "4.0.1-rc2-24027",
        "System.Runtime.InteropServices": "4.1.0-rc2-24027",
        "Microsoft.DotNet.InternalAbstractions": "1.0.0-rc2-002702",
        "System.Reflection.Extensions": "4.0.1-rc2-24027",
        "System.Diagnostics.Debug": "4.0.11-rc2-24027"
      }
    }
  }

Project.json.lock tells the compiler exactly where to look for our dependencies. You can produce it with „dotnet restore”. Sometimes VS will do this for you, sometimes you will have to do this on your own.

New dependencies

There are at least 3 types of dependencies. Project, package and build. Sample:

 "dependencies": {
    "BenchmarkDotNet": {
      "target": "project",
      "version": "1.0.0-*"
    }
  }

When you want to add some dependency then you just add in in the right place in project.json. It depends on which platforms the library that you would like use supports.

  • If it supports all frameworks then you just need to move the dependencies to common dependencies (same level as frameworks, same thing applies to frameworkAssemblies).
  "frameworks": {
    "net40": { },
    "netstandard1.5": { }
  },
  "dependencies": {
	"someCommonDependency": "it's version"
  }
  • If there are few different packages/version then you need to specify both dependencies in explicit way:
    "frameworks": {
	"net40": { 
		"dependencies": {
			"someCommonDependency": "exact version that supports net40"
	  }
    },
    "netstandard1.5": { 
		"dependencies": {
			"someCommonDependency": "exact version that supports netstandard1.5"
	  }
    }
  }
  • If the desired package does not support all frameworks, then you add it as dependency to specific framework, but in code you use ugly #if #endif to exclude it for other compilation targets. We define #CLASSIC, #DNX, #CORE and #RC1 & #RC2. In other OSS projects you can meet more complex names like #NET40, #NET451, #DNX451 or #DNXCORE50.
#if CLASSIC
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace BenchmarkDotNet.Loggers
{
    internal class MsBuildConsoleLogger : Logger
    {
        private ILogger Logger { get; set; }

        public MsBuildConsoleLogger(ILogger logger)
        {
            Logger = logger;
        }

        public override void Initialize(IEventSource eventSource)
        {
            // By default, just show errors not warnings
            if (eventSource != null)
                eventSource.ErrorRaised += OnEventSourceErrorRaised;
        }

        private void OnEventSourceErrorRaised(object sender, BuildErrorEventArgs e) =>
            Logger.WriteLineError("// {0}({1},{2}): error {3}: {4}", e.File, e.LineNumber, e.ColumnNumber, e.Code, e.Message);
    }
}
#endif
  • If it is not a package, but dll/exe file then you need to create wrap for it. You can do this for VS, but currently it will not work with dotnet cli, since it is going to produce wrong path. This is why I recommend to do this manually. You just need to create new folder in solution's root, then put project.json file there and add the folder to global.json file. Sample wrap file:
{
  "version": "1.0.0-*",
  "frameworks": {
    "net40": {
      "bin": {
        "assembly": "../CLRMD/Dia2Lib.dll"
      }
    }
  }
}

F#

We have full F# support, all you have to do is to run dotnet restore to download the compilers etc.

Chat room

Join the chat at https://gitter.im/PerfDotNet/BenchmarkDotNet