Search code examples
c#code-contractsroslynasp.net-core

Code Contracts with no dlls on disk on asp.net 5/vnext


Asp.Net vnext/5 uses roslyn for on-the-fly compilation, not producing any assemblies at all. Most code contract tools use compile-time code transformations to translate contracts to runtime checks.

How is it going to work with Asp.Net 5? I love using attibute-based contracts like [NotNull] on parameters, but all these things don't work if you have no compilation step and no assemblies.

Any ideas where this is going to?


Solution

  • The default behavior when building is as you say, but you do still have the option to create output files if you'd rather.

    If you're working at the command line, go to the location of your project.json file and use the kpm build command. This will generate Nuget packages as well as leaving the dlls in the familiar locations for each framework you're targeting.

    For example, if you're targeting aspnet50, you could end up with \bin\Debug\YourProject.Version.nupkg and \bin\Debug\aspnet50\YourProject.dll.

    The Nuget package will contain the necessary assemblies for each framework you are targeting, and you will have a directory inside of the build configuration folder (e.g. Debug) for each framework with the DLLs.

    If you are using the Visual Studio 2015 preview, you can change the default build behavior for a project to do the same thing for you each build. To do that, simply right click on the project in the Solution Explorer and select Properties. On the Build tab, there is a checkbox for creating build outputs that will have visual studio build the packages and write the DLLs on each build the same as if you used kpm build manually.