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

其他回答

默认的VS2015模板的问题是编译器实际上没有复制到tfr\bin\roslyn\目录中,而是复制到{outdir}\roslyn\目录中

在.csproj文件中添加以下代码:

<Target Name="CopyRoslynFiles" AfterTargets="AfterBuild" Condition="!$(Disable_CopyWebApplication) And '$(OutDir)' != '$(OutputPath)'">
    <ItemGroup>
      <RoslynFiles Include="$(CscToolPath)\*" />
    </ItemGroup>
    <MakeDir Directories="$(WebProjectOutputDir)\bin\roslyn" />
    <Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)\bin\roslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" />
</Target>

为了防止构建也将Roslyn文件复制到bin目录,您还必须注释掉位于Web应用程序项目顶部的这一行:

<!--  <Import Project="..\..\..\DAS\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\..\..\DAS\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" /> -->

我在服务器上安装应用程序时遇到了同样的问题,而在localhost上一切都很完美。

这些解决方案都不奏效,我总是犯同样的错误:

Could not find a part of the path 'C:\inetpub\wwwroot\myApp\bin\roslyn\csc.exe'

我最后是这样做的:

在我的安装项目中,右clic,查看>文件系统 创建一个bin/roslyn文件夹 选择添加>文件,并添加包\Microsoft.Net.Compilers.1.3.2\tools中的所有文件

这解决了我的问题。

正如GitHub上Roslyn项目的一个问题所指出的那样,一个解决方案(对我有用)是简单地在Visual Studio中卸载和重新加载项目。

“bin\roslyn”文件夹没有在构建或重新构建时创建,直到我重新加载项目。

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