gpt4 book ai didi

.net - 通过 CodeDomProvider 使用 AssemblyCopyrightAttribute 或 AssemblyCompanyAttribute 时出现编译错误

转载 作者:行者123 更新时间:2023-12-02 15:22:38 25 4
gpt4 key购买 nike

我认为发生了一些愚蠢的事情,因为剩余的程序集级属性可以很好地包含在内,但每当声明 AssemblyCopywriteAttributeAssemblyCompanyAttribute 时,都会导致 CS0116 和 CS1730 错误。鉴于代码不包含任何方法声明,我不知道如何 CS0116适用,并且没有散布类型定义,因此不确定如何 CS1730是适用的。

错误

Error Number: CS0116
Error Text: A namespace cannot directly contain members such as fields or methods

Error Number: CS1730
Error Text: Assembly and module attributes must precede all other elements defined in a file except using clauses and extern alias declarations

源文件:

using System;
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: ComVisible(false)]
[assembly: CLSCompliant(false)]
[assembly: AssemblyCompany("My Company")]; // this results in a compile time error
[assembly: Guid("9d8271d9-957f-46dc-bcc6-1055137b4fad")]
[assembly: AssemblyTitle("CCDA MAP")]
[assembly: AssemblyDescription("The mapping logic to source a CXD and populate a CCDA")]
[assembly: AssemblyCopyright("My Company 2015")]; // this results in a compile time error
[assembly: AssemblyCulture("en-US")]
[assembly: AssemblyVersion("2.2.0")]
[assembly: AssemblyFileVersion("2.2.0.123")]
[assembly: AssemblyConfiguration("DEBUG")]
[assembly: AssemblyMetadataAttribute("Built","06/27/2015")]
[assembly: AssemblyMetadataAttribute("Host","JORMUNGANDR")]
[assembly: AssemblyMetadataAttribute("The answer","42")]
[assembly: AssemblyMetadataAttribute("Document Type","CCDA")]
[assembly: AssemblyMetadataAttribute("Document Spec Version","2.0")]

编译逻辑

CodeDomProvider provider = CodeDomProvider.CreateProvider("C#");
var source = Directory.GetFiles(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"codedom"),"*.cs").ToList().Dump("Map Source").Select(i=>File.ReadAllText(i)).ToArray();
var parameters = new CompilerParameters{ GenerateInMemory = true, OutputAssembly = string.Format("Map.dll",count),TreatWarningsAsErrors = true, WarningLevel = 4};
parameters.ReferencedAssemblies.Add("mscorlib.dll");
var results = provider.CompileAssemblyFromSource(parameters, source);

最佳答案

该错误是由文本中错误的分号引起的:

[assembly: AssemblyCopyright("My Company 2015")]; // this results in a compile time error

应该是:

[assembly: AssemblyCopyright("My Company 2015")] // this does not result in a compile time error

还有:

[assembly: AssemblyCompany("My Company")]; // this results in a compile time error

应该是:

[assembly: AssemblyCompany("My Company")] // this does not result in a compile time error

删除它们可以清除您看到的错误。

关于.net - 通过 CodeDomProvider 使用 AssemblyCopyrightAttribute 或 AssemblyCompanyAttribute 时出现编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31092180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com