c# - 有没有办法在没有 nuget 包的情况下使用 Microsoft.CodeDom.Providers.DotNetCompilerPlatform?
问题描述
我编写了一个 Asp.Net Webforms 应用程序 (aspx)。该应用程序的目标是 DotNet 4.72。在应用程序中,我使用元组,因此为了使语法正常工作,我安装了块包 Microsoft.CodeDom.Providers.DotNetCompilerPlatform 版本 2.0.0
不起作用的代码如下所示:
public (Person, string, Int) Foo()
{
return (new Person(), "Hello", 42);
}
有人告诉我用程序集引用替换 nugget 包,但我找不到让它工作的方法。我做的步骤是:
- 保存文件:
- Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll
- Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll.refresh
- Microsoft.CodeDom.Providers.DotNetCompilerPlatform.xml
将包复制到项目中的文件夹中。
- 使用 NuGet 包管理器删除了块包。
结果:我得到语法的构建错误:
error CS1031: Type expected
error CS1519: Invalid token '(' in class, struct, or interface member declaration
error CS1519: Invalid token ',' in class, struct, or interface member declaration
error CS1519: Invalid token ',' in class, struct, or interface member declaration
error CS1519: Invalid token ')' in class, struct, or interface member declaration
error CS1520: Method must have a return type
- 在 web.config 文件中添加了以下内容:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4"
compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
然后我得到一个编译错误:
Could not find a part of the path 'C:\Users\myUserName\source\repos\WebSite1\WebSite1\bin\roslyn\csc.exe'.
我可以在不使用 NuGet 包的情况下使用这个包吗?如果是这样,我该怎么做?
提前致谢。
解决方案
尝试将 dll 文件复制到 bin 目录或在项目中创建一个 lib 文件夹并从那里引用它。还要确保右键单击dll文件->“属性-->复制到输出目录-->始终复制”被选中
推荐阅读
- python - 在套接字库 (Python) 中获取错误的 IP - [从另一个适配器获取信息]
- sql - Oracle SQL:如何从组中查找记录
- reactjs - 在 React Native 中构建导航结构
- azure-data-factory - 如何使 Azure 数据工厂中的投影选项卡的导入架构工作?
- gremlin - Gremlin 按边分组计数,然后还选择除计数本身之外的其他属性
- javascript - React 和 Redux:用 HTML 标签包装 React Map 函数
- perl - 试图在同一个文件中的两个两个模式之间组合多行
- android - 将数据库表存储为 Xamarin Forms 中的备份以在设备之间使用
- angular - 为什么指令属性不适用于 img html 标签?
- reactjs - 如何在 typescript ssr 的 renderToString 中使用 StaticRouter?