1 回答

TA貢獻1815條經驗 獲得超13個贊
正如您已經提到的,快速解決方法是使用包管理器?>>Tools
來運行Nuget Package Manager
Package Manager Console
Update-Package?Microsoft.CodeDom.Providers.DotNetCompilerPlatform?-r
但另一種解決方案(我認為更可靠)是刪除項目Web.config文件的屬性。(Web.config與您的文件位于同一目錄中.csproj。)
Web.config在文本編輯器(或 Visual Studio 中)中打開文件。
- 在標簽中configuration | system.codedom | compilers | compiler language="c#;cs;csharp",完全刪除該type屬性。
<?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>
簡而言之,刪除以 開頭的行type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft。
(據推測,相同的修復方法適用于 Visual Basic 和 Csharp,但我還沒有嘗試過。)
Visual Studio 將處理剩下的事情。不再Server Error in '/' Application。
在我在上面的 zip 文件中提供的示例代碼中,HTTP Error 403 當您點擊Ctrl+時,您將得到F5。
嘗試http://localhost:64195
在您的網絡瀏覽器中替換為http://localhost:64195/api/products
.
Web API 現在顯示應有的樣子:
作為挑釁,我什至嘗試刪除package
Visual Studio 解決方案的整個目錄。
當我(重新)構建它時,它就會自動且默默地重新創建。
- 1 回答
- 0 關注
- 265 瀏覽
添加回答
舉報