我正在try 创建一个.NET 6.0应用程序,它将能够编译另一个.NET 6.0应用程序.问题是,罗斯林似乎没有看到参考文献.
以下是我从罗斯林那里收到的一些错误:
Invalid assembly name: The name contains invalid characters.
Cannot find the name of the type or namespace 'List<>'
Cannot find the name of the type or namespace 'Task'
Cannot find the name of the type or namespace 'StreamReader'
Name 'Environment' does not exist in the current context
Name 'String' does not exist in the current context
Name 'Array' does not exist in the current context
Type 'MarshalByRefObject' is defined in an unreferenced assembly. You need to add a reference to the 'System.Runtime' assembly
Type 'Uri' is defined in an unreferenced assembly. You need to add a reference to the 'System.Runtime' assembly
这是我的编译器代码:
var syntaxTree = CSharpSyntaxTree.ParseText(source);
var references = new[]
{
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
MetadataReference.CreateFromFile(Path.Combine(dp, "BouncyCastle.Crypto.dll"))
};
var compilation = CSharpCompilation.Create(output)
.WithOptions(new CSharpCompilationOptions(OutputKind.WindowsApplication))
.AddReferences(references)
.AddSyntaxTrees(syntaxTree);
EmitResult emitResult = compilation.Emit(output);
我已经try 过这样的东西:
var references = new[]
{
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
MetadataReference.CreateFromFile(typeof(HttpClient).Assembly.Location),
MetadataReference.CreateFromFile(typeof(System.Net.HttpWebRequest).Assembly.Location),
MetadataReference.CreateFromFile(typeof(System.Text.RegularExpressions.Regex).Assembly.Location),
MetadataReference.CreateFromFile(typeof(List<>).Assembly.Location),
MetadataReference.CreateFromFile(typeof(Task).Assembly.Location),
MetadataReference.CreateFromFile(typeof(StreamReader).Assembly.Location),
MetadataReference.CreateFromFile(typeof(Environment).Assembly.Location),
MetadataReference.CreateFromFile(typeof(string).Assembly.Location),
MetadataReference.CreateFromFile(typeof(MarshalByRefObject).Assembly.Location),
MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location),
MetadataReference.CreateFromFile(Path.Combine(dp, "BouncyCastle.Crypto.dll"))
};
但它似乎并没有奏效.
有什么主意吗?