我正在尝试运行ASP。NET MVC(模型-视图-控制器)项目从TFS (Team Foundation Server)源代码控制检索。我已经添加了所有程序集引用,我能够成功地构建和编译,没有任何错误或警告。

但是我在浏览器中得到以下错误:

找不到路径的一部分 “C: \ B8akWorkspace \ B8akProject \ B8akSolution \ B8AK.Portal \ bin \ roslyn \ csc.exe”。

以下是错误页面的完整截图。

经过几天的研究,我了解到Roslyn是一个提供高级编译特性的. net编译器平台。但是,我不明白为什么我的构建试图找到\bin\roslyn\csc.exe,因为我没有配置任何与roslyn相关的东西。我也没打算让罗斯林参与我的项目。


当前回答

很多答案都涉及到Nuget包和/或清理和重新加载你的项目。

如果您有WCF服务引用和无效端点,也可以得到此错误消息。确保您的端点是正确的,并在.config和从GUI配置服务引用时使用正确的端点更新服务配置。

其他回答

TL;博士

在包管理器控制台中运行:

更新- package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r

更多的信息

这个问题与Visual Studio本身无关,因此建议添加构建步骤来复制文件的答案是一种变通方法。与手动向项目添加编译器二进制文件相同。

Roslyn编译器来自一个NuGet包,在该包的某些版本中有/曾经有一个bug(我不知道具体是哪些版本)。解决方案是重新安装/升级该包到无bug的版本。最初,在我写回2015年的答案之前,我通过在特定版本安装以下包来修复它:

Microsoft net.compilers 1.1.1 Microsoft. CodeDom. Will the DotNetCompilerPlatform 1.0.1

然后我查看了.csproj,并确保包的路径是正确的(在我的情况下..\..\packages\*.*)在标签<ImportProject>在顶部和<Target>与名称“EnsureNuGetPackageBuildImports”在底部。这是在MVC 5和。net Framework 4.5.2上。

0. 权宜之计

正如目前票数最高的答案所指出的, 快速修复是使用包管理器,Tools > Nuget package Manager >包管理器控制台,以运行

更新- package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r

1. 代码来重现错误

下面是重现错误的代码: https://user.it.uu.se/%7Ehesc0353/SrvrErr-reproduce.zip (来自 https://github.com/aspnet/AspNetDocs/tree/master/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client/sample/server/ProductsApp)

考虑尝试上面zip文件中提供的示例代码。 如果没有更改,则按Ctrl+F5重新生成 这个错误。

2. 更健壮的解决方案

另一种解决方案是从项目的 网络。配置文件。 (Web。Config与.csproj文件在同一目录下。) 这将自动和静默地重新创建您的包,如果它们 人失踪。

打开网络。配置文件在文本编辑器或Visual Studio。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings></appSettings>
  ...
  <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=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>
</configuration>

在标签配置>系统。Codedom >编译器> 编译语言="c#;cs;csharp",完全删除 类型属性。 -简而言之,删除开始的行 type = " Microsoft.CodeDom.Providers.DotNetCompilerPlatform。CSharpCodeProvider。 1

Visual Studio将负责其余的工作。 -没有更多的服务器错误在'/'应用程序。

3.HTTP错误403

在上面的例子中,按Ctrl+F5 现在将导致HTTP错误403。

试着在浏览器中替换http://localhost:64195 http://localhost: 64195 / api /产品。 web API现在正确显示:


作为挑衅,我尝试将整个包目录从 Visual Studio项目。 一旦项目完成,它就会自动且无声地重新创建 重建。

参考文献

重现错误的项目文件 原项目


1 .想必同样的修复也适用于Visual Basic 至于c#,但我还没有尝试过。

很多答案都涉及到Nuget包和/或清理和重新加载你的项目。

如果您有WCF服务引用和无效端点,也可以得到此错误消息。确保您的端点是正确的,并在.config和从GUI配置服务引用时使用正确的端点更新服务配置。

这是Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.6的一个已知问题。降级到1.0.5为我解决了这个问题。

在我的情况下,我有问题在詹金斯,当它试图部署它在章鱼有以下错误:

MSBUILD : OctoPack error OCT-1676060969: Failed to build the path for '\bin\roslyn\csc.exe' relative to 'T:\workspace\machine.engine\Machine.engine.Test': Invalid URI: The format of the URI could not be determined.. See the inner exception for more details. [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969: System.Exception: Failed to build the path for '\bin\roslyn\csc.exe' relative to 'T:\workspace\machine.engine\Machine.engine.Test': Invalid URI: The format of the URI could not be determined.. See the inner exception for more details. ---> System.UriFormatException: Invalid URI: The format of the URI could not be determined. [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969:    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969:    at System.Uri..ctor(String uriString) [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969:    at OctoPack.Tasks.Util.OctopusPhysicalFileSystem.GetPathRelativeTo(String fullPath, String relativeTo) in Z:\buildAgent\workDir\20ba9f2e0d5e4022\source\OctoPack.Tasks\Util\OctopusPhysicalFileSystem.cs:line 211 [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969:    --- End of inner exception stack trace --- [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969:    at OctoPack.Tasks.Util.OctopusPhysicalFileSystem.GetPathRelativeTo(String fullPath, String relativeTo) in Z:\buildAgent\workDir\20ba9f2e0d5e4022\source\OctoPack.Tasks\Util\OctopusPhysicalFileSystem.cs:line 224 [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969:    at OctoPack.Tasks.CreateOctoPackPackage.AddFiles(XContainer nuSpec, IEnumerable`1 sourceFiles, String sourceBaseDirectory, String targetDirectory, String relativeTo) in Z:\buildAgent\workDir\20ba9f2e0d5e4022\source\OctoPack.Tasks\CreateOctoPackPackage.cs:line 443 [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969:    at OctoPack.Tasks.CreateOctoPackPackage.Execute() in Z:\buildAgent\workDir\20ba9f2e0d5e4022\source\OctoPack.Tasks\CreateOctoPackPackage.cs:line 190 [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
Done Building Project "T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj" (default targets) -- FAILED

导致

在花了一段时间后,我使用了一个内部开发的组件,该组件使用Microsoft.Net.Compilers。内部组件使用Microsoft.Net.Compilers的原因是为了克服这个问题(c#:抛出无效的表达式编译),并以这种方式解决(如何在Visual Studio 2015中使用c# 7 ?)这导致,当我在主程序上安装组件时,Microsoft.Net.Compilers会自动添加。

解决方案

我的工作是,卸载以下从我们的内部组件(以下@malikKhalil回答)

PM> Uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
PM> Uninstall-package Microsoft.Net.Compilers

并且在Jenkins中选择了c# 7编译器而不是c# 6和重建,这是为了确保一切都能正常工作和构建。

最后,在我的主程序中,我尝试更新我的内部组件。一切都比重新建造好。它没有任何问题或问题。