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

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

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

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

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


当前回答

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#,但我还没有尝试过。

其他回答

我在Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.06上有这个错误,但在@ prisoner erzero上也有1.0.7的错误。然而,当微软发布1.0.8 2017-10-18时,它终于开始为我工作了,我不必降级。

https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/

默认的VS2015模板的问题是编译器实际上没有复制到{outdir}_PublishedWebsites\tfr\bin\roslyn\目录中,而是复制到{outdir}\roslyn\目录中。这可能与您的本地环境不同,因为AppHarbor使用输出目录构建应用程序,而不是“就地”构建解决方案。

要修复它,在xml块<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

<PropertyGroup>
  <PostBuildEvent>
    if not exist "$(WebProjectOutputDir)\bin\Roslyn" md "$(WebProjectOutputDir)\bin\Roslyn"
    start /MIN xcopy /s /y /R "$(OutDir)roslyn\*.*" "$(WebProjectOutputDir)\bin\Roslyn"
  </PostBuildEvent>
</PropertyGroup>

参考:https://support.appharbor.com/discussions/problems/78633 -斜面-构建- aspnet - mvc项目生成——从vstudio - 2015企业

The answer for this is different for Website project and Web application Project. The underlying issue is same that NuGet package is behaving differently on different machine. It may be rights issue or some execution policy which stops it from copying to Bin folder As you know Roslyn is new compiler. you should have it in Bin folder for these Projects Go to your website NuGet Packages check this Folder Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0 \code\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0 Do you see it ? Can you see code\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\tools\RoslynLatest in it Now as part of compiling this Folder should get copied to your website under bin like this. \code\WebSite1\Bin\Roslyn some how that is not happening for you . Try running Visual studio as Admin . Copy Roslyn folder manually. Try uninstall and install of NuGet Package. Remember this package compile your folder and if its not there you cannot compile anything and so you cannot add anything too. Try copying this package to offline version tools -> options-> nuget package Manager->Package source-> Microsoft Visual Studio Offline Packages C:\Program Files (x86)\Microsoft SDKs\NuGetPackages

以我为例,在尝试任何其他解决方案之前,我切换到“发布”配置,重新创建(文件夹被创建),然后切换回“调试”,而文件夹保持不变。

这是从旧解决方案的源代码控制中签出的,显然原始(自动)包恢复和构建项目并没有在bin目录中创建该文件夹。

注意,在撰写本文时,被指责的组件已经达到v.2。

我在发布管道中遇到了这个问题(它产生了一个_PublishedWebsites目录),并将其用作项目中的目标:

<Target Name="CopyRoslynCompilerFilesToPublishedWebsitesDirectory" AfterTargets="AfterBuild" Condition="Exists('$(OutDir)\_PublishedWebsites\$(TargetName)')">
    <Copy SourceFiles="@(RoslyCompilerFiles)" DestinationFolder="$(OutDir)\_PublishedWebsites\$(TargetName)\bin\roslyn" ContinueOnError="true" SkipUnchangedFiles="true" />
</Target>

缺点是输出中将有两个Roslyn文件的副本。