This is a simple example of using Roslyn to compile some code from a string,
load it into the currently executing AppDomain
, and activate and invoke the code.
It is based on this article
and was adapted for the slightly different API surface area on .net core.
This was written to work with .NET Core RC2.
In order to resolve the prerelease dependencies, you'll have to add the aspnetcidev
myget feed.
You can do so by adding or modifying the
~/.config/NuGet/NuGet.Config
file (on mac) to include the AspNetCiDev
key listed below:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<activePackageSource>
<add key="AspNetCiDev" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" />
<add key="Official NuGet Gallery" value="https://www.nuget.org/api/v2/" />
</activePackageSource>
</configuration>
git clone https://github.com/joelmartinez/dotnet-core-roslyn-sample.git
cd dotnet-core-roslyn-sample
dotnet restore && dotnet run