找不到文件... bin\roslyn\csc.exe [英] Could not find file ... bin\roslyn\csc.exe
问题描述
在 Visual Studio 2017 中,当点击 Ctrl+F5 运行我的ASP.NET Framework Web API 服务器,我得到:
<块引用>找不到文件... bin\roslyn\csc.exe:
运行 Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r
在包管理器控制台中不是永久性修复,因为当软件包文件丢失时,服务器错误再次出现.我怎样才能一劳永逸地摆脱这个错误,以便所需的包一旦我重新打开、构建、并运行我的 Visual Studio 解决方案?
重现错误的代码:
但是另一种解决方案(我认为更可靠)是删除项目的 Web.config
文件的属性.(Web.config
与您的 .csproj
文件在同一目录中.)
在文本编辑器中(或在 Visual Studio 中)打开 Web.config
文件.
- 在标签 configuration |system.codedom |编译器|compiler language="c#;cs;csharp"
,完全去掉type
属性.
简而言之,删除以 type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft
开头的行.
(据推测,相同的修复程序适用于 Visual Basic 和 Csharp,但我还没有尝试过.)
Visual Studio 将负责其余的工作.不再出现 /"应用程序中的服务器错误
.
在我在上面的 zip 文件中提供的示例代码中,您现在将收到 HTTP 错误 403
当你点击 Ctrl+F5.
尝试用 http://localhost:64195/api/products
替换 Web 浏览器中的 http://localhost:64195
.
Web API 现在显示为它应有的样子:
作为挑衅,我什至尝试删除我的 Visual Studio 解决方案的整个 package
目录.
一旦我(重新)构建它,它就会自动且无声地重新创建.
In Visual Studio 2017, when hitting Ctrl+F5 to run my ASP.NET Framework Web API server, I get:
Could not find file ... bin\roslyn\csc.exe:
Running Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r
in the package manager console is not a permanent fix in the sense that the
server error appears again when the package files are missing.
How can I get rid of this error once and for all so that the needed packages
are automatically (and silently) reinstalled as soon as I reopen, build,
and run my Visual Studio solution?
Code to reproduce the error:
http://henke.atwebpages.com/SrvrErr-reproduce.zipfile
1
(Originally from
https://github.com/aspnet/AspNetDocs/tree/master/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client/sample/server/ProductsApp)
1 Please rename the extension from zipfile
to zip
.
As you already mention,
the quick fix is to use the package manager,
Tools
> Nuget Package Manager
> Package Manager Console
, to run
Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r
as pointed out by https://stackoverflow.com/questions/32780315#34391473
But an alternative solution (which I consider to be more robust) is to remove an attribute of your project's Web.config
file.
(Web.config
is in the same directory as your .csproj
file.)
Open the Web.config
file in a text editor (or inside Visual Studio).
- In the tag configuration | system.codedom | compilers | compiler language="c#;cs;csharp"
, completely remove the type
attribute.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- ... -->
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.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=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
</configuration>
In short, remove the line that starts with type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft
.
(Presumably, the same fix works for Visual Basic as well as for Csharp, but I have not tried it.)
Visual Studio will take care of the rest. No more Server Error in '/' Application
.
In the example code I provided in the zip file above you will now get HTTP Error 403
when you hit Ctrl+F5.
Try replacing http://localhost:64195
in your web browser with http://localhost:64195/api/products
.
The web API now displays as it should:
As a provocation, I even tried removing the whole package
directory of my Visual Studio solution.
It was automatically and silently recreated as soon as I (re-)built it.
这篇关于找不到文件... bin\roslyn\csc.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!