这是一个非常简单的代码,它生成了一个可以从可移植类库引用的dll,但是,它容易出错,因为当我添加任何引用时,它接受非可移植引用。 我如何确定我正在尝试生成的是否在可移植配置文件中? 以下是代码:
using System.IO;
using Roslyn.Compilers;
using Roslyn.Compilers.CSharp;
namespace Ros1
{
class Program
{
static void Main(string[] args)
{
SyntaxTree tree = SyntaxTree.ParseText(
@"using System;
namespace HelloWorld
{
public class A
{
public int Sum(int a, int b)
{
return a + b;
}
}
}");
var co = new CompilationOptions(OutputKind.DynamicallyLinkedLibrary);
var compilation = Compilation.Create("HelloWorld", co)
.AddReferences(MetadataReference.CreateAssemblyReference("mscorlib"))
.AddSyntaxTrees(tree);
using (var file = new FileStream("Sum.dll", FileMode.Create))
{
compilation.Emit(file);
}
}
}
}