我正在尝试运行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 PM破坏了Rosalyn行为。如果Microsoft.CodeDom.Providers存在更新,则单击“工具”> NuGet包管理器>管理解决方案的NuGet包。DotNetCompilerPlatform, Microsoft.Net。编译器,或者Microsoft.Net.Compilers.netcore,更新它们,解决方案就会崩溃!这是因为ASP Sites模板在项目创建时被设置为使用特定的版本。要查看问题,请单击“解决方案资源管理器”中的“显示所有文件”。

Fix

在项目创建时$(WebProjectOutputDir)\bin不存在,因此当Rosalyn被NuGet添加为依赖项时,它会正确安装它。在更新解决方案包之后,$(WebProjectOutputDir)\bin目录看起来像这样:

$ (WebProjectOutputDir) \ bin \ bin \罗莎

最简单的方法是剪切并粘贴rosalyn到合适的位置,然后删除多余的bin文件夹。现在可以刷新页面,然后加载站点。

其他回答

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

下面为我解决了这个问题:

更新到Visual Studio 2017的最新版本(使用安装程序应用程序) 清理并重新构建解决方案

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

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

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

这里有一个更MSBuild的方法。

<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目录中(而不是在文件夹中)。不过,这款应用似乎还能用。

在尝试了所有没有雪茄的修复后,我在Visual Studios中更新了这个Nuget包:

Microsoft.CodeDom.Providers.DotNetCompilerPlatform

我的是从1.0.0到2.0.0供参考(错误不再显示)