简体   繁体   中英

Is there a way to use Microsoft.CodeDom.Providers.DotNetCompilerPlatform without a nuget package?

I've written an Asp.Net Webforms app (aspx). The app is targeting DotNet 4.72. In the app, I'm using Tuples, so in order for the syntax to work, I've installed the nugget package Microsoft.CodeDom.Providers.DotNetCompilerPlatform version 2.0.0

the code that is not working looks like this:

public (Person, string, Int) Foo() 
   {
      return (new Person(), "Hello", 42);
   }

I was told to replace the nugget package with assembly reference, and I can't find a way to make it work. The steps I did are:

  1. Save the files:
  • Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll
  • Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll.refresh
  • Microsoft.CodeDom.Providers.DotNetCompilerPlatform.xml

of the package to a folder in the project.

  1. Removed the nugget package using the NuGet package manager.

Result: I get build errors for the syntax:

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
  1. Added the following entire to web.config file:

 <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=\&quot;Web\&quot; /optionInfer+" /> </compilers> </system.codedom>

Then I got a compile error:

Could not find a part of the path 'C:\Users\myUserName\source\repos\WebSite1\WebSite1\bin\roslyn\csc.exe'.              

Can I use this package without using NuGet package? If so, how do I do this?

Thanks in advance.

try copy dll files to bin directory or create a lib folder in project and reference it from there. Also make sure to right click dll file --> "properties --> copy to output directory --> copy always" is selected

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM