Using .NET Core Binaries


#1

It is unclear to me how I can use the .NET Core binaries and how they relate to the full .NET framework. For example I have a console application that runs using the full .NET Framework. I want to modify the app so that I can use the mscorlib.dll, coreCLR.dll, and corefx libraries I have built from source. How difficult is this, and is there any documentation that could help me?


Putting coreCLR and coreFx together
#2

Hi @bjjzqd,
Have you tried the Console app walkthrough described in this post? http://blogs.msdn.com/b/dotnet/archive/2015/02/03/coreclr-is-now-open-source.aspx

From the post:

The easiest way to try out CoreCLR is via the prototype of the CoreCLR-based console application. You can get it from our new corefxlab repo. In order to use it, you can just clone, build, and run via the command line:

git clone https://github.com/dotnet/corefxlab
cd .\corefxlab\demos\CoreClrConsoleApplications\HelloWorld
nuget restore
msbuild  
.\bin\Debug\HelloWorld.exe

Of course, once you have cloned the repo you can also simply open the HelloWorld.sln file and edit the code in Visual Studio. Please note that debugging is not yet supported, but debuggers are only for people who make mistakes anyway, right?

You can also modify CoreCLR and make the Console app run against the locally built version of it. At this point, the build automation isn’t that great but here is how you can do that manually with the sources we have today:

1. Modify CoreCLR to your heart’s content
2. Build CoreCLR via build.cmd x64 release
3. Copy the following files from coreclr\binaries\x64\release to corfxlab\demos\CoreClrConsoleApplications\HelloWorld\NotYetPackages\CoreCLR:
- coreclr.dll
- CoreConsole.exe
- mscorlib.dll
4. Rebuild HelloWorld.sln (either using the command line or in VS)

Hope this helps (if not, I’ll lasso another team member :smile: ),
-B


#3

I want to use ArrayList in my console program and it’s in CoreFx System.Collections.NonGeneric. I copied the System.Collections.NonGeneric.dll to NotYetPackages directory but running into lots of build errors.

I am trying to build with VS15 CTP6.

I couldn’t build System.Collections.NonGeneric with VS15 and I had to build it on other system with VS13.

Basically I want to write a console program with ArrayList and XML document classes.

Thank you for your help


#4

Hi Cheers,
It’s unclear whether your goal is to run a modified version of the assemblies (like bjjzqd is asking above) or just want to use System.Collections.ArrayList in a console app.

If you don’t want to run private binaries, it’s very easy in CTP6. Note I’m using slightly newer bits, so versions may vary, but all you need to do is to add a reference in your project.json file (or, via GUI, from “References / ManageNugetPackages”). Once you’ve done that, your project.json will look something like this:

"frameworks" : {
    "aspnetcore50" : { 
        "dependencies": {
            "System.Console": "4.0.0-beta-*",
            "System.Collections.NonGeneric": "4.0.0-beta-*"
        }
    }
}

… and that’s it. (note * versioning will work but will “float” to the newest it finds on your feed) I can now use any of the types in System.Collections.NonGeneric. I’ve also deleted the aspnet50 section here because I’m only interested in building / running on Core framework in this example.

Hope this helps. The new project system can be daunting at first, but one gets accustomed to it.

-Matt


#5

Hi @bjjzqd,
The approach in the blog post Beth linked works for me on my local setup, but if you’re using the ASP.NET Project templates and tooling, there’s another, albeit not supported and undocumented way to achieve this. If you use KVM (get instructions for this from https://github.com/aspnet/home/, you want the “master” branch version) you can manage and view the paths for your ASP.NET Core Runtime versions. You’ll be able to set the default version as well as see which one is already selected. By figuring out (and potentially cloning w/ different version #) the copy of your runtime you see under, for instance c:\Users<your user name>.k\runtimes\kre-coreclr-win-x64.1.0.0-… path, you can select a copy that uses your specific versions. This lets you work directly with Visual Studio and automatically sets up debugging, host executable, etc. Again, this isn’t an “official” way to do it, but if you want to use your personal changes in an ASP.NET 5 Web app, this is one way to do it. If you mess up your runtime, you can simply delete the folder and use “kvm install” to restore it.

Hope this helps,
Matt


#6

Matt, thank you.

I want to add private binary but I can start with public corefx package.

I am still having problems to add System.Collections.NonGeneric to project.json file. I’ve tried to add Nuget package using Nuget Manager but I couldn’t find at System.Collections.NonGeneric. I tried all three nuget sources.

Then I copied System.Collections.NonGeneric.dll from corefx (built with VS13 on different deb box) to a folder under my project but the intellisense didn’t work at project.json. I don’t see any option at “add reference” to add this dll directly to project.

I only have aspnetcore5 in project.json file.

"frameworks" : {
    "aspnetcore50" : { 
        "dependencies": {
            "System.Console": "4.0.0-beta-*"
        }
    }
}

‘’’


#7

Couple things here:

  • Nuget.org definitely has http://www.nuget.org/packages/System.Collections.NonGeneric/4.0.0-beta-22605 , but perhaps you have the setting to pick up pre-release packages (See checkbox in Nuget Package Manager UI) unchecked? Either way, if you have the K tools on the command line you can simply, with the project.json entry I listed before, do “kpm restore”. (if you don’t have them, get KVM and make sure to kvm use / have a default aliased entry).

  • If you want to work with ASP.NET VNext and build packages that can be used in the Core profile, you’re going to need to build them with VS 2015 or an MSBuild trick like in the blog post. VS 2013 does not know currently how to target the specific profile needed for these.

  • Loosely including DLLs by copying them into your project just isn’t going to work. Adding references to DLLs directly similarly is not supported. For Core50 packages, you need to have your dependencies expressed as NuPkgs or other VNext project references.


#8

Matt, this worked for me. Thanks. I was able to add Collections.NonGeneric pacakge, compile and deploy it.

But this looks more like web app. What I really want is something similar to corfxlab\demos\CoreClrConsoleApplications\HelloWorld. When I build, I get to see helloWorld.exe and other coreCLR dlls in bin\debug folder.

In corefxlab helloworld project, if I try to search and add System.Collections.NonGeneric, I get the following error. How do I overcome this?

Could not install package 'System.Globalization 4.0.10-beta-22231'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.


#9

We can not use corefxlab helloworld to build console app with corefx components yet. Hopefully we will be able to do it with next VS 2015 release.

Check corefx issues


.NET Foundation Website | Blog | Projects | Code of Conduct