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

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

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

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

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


当前回答

所以,罗伯·坎农的回答基本上对我有用,但我不得不调整一些选项。具体来说,我必须删除目标上的条件,并更改Include属性,因为当项目在构建服务器上构建时,$CscToolPath为空。奇怪的是,$CscToolPath在本地运行时不是空的。

<Target Name="CopyRoslynFiles" AfterTargets="AfterBuild" >
  <ItemGroup>
    <RoslynFiles Include="$(SolutionDir)packages\Microsoft.Net.Compilers.1.1.1\tools\*" />
  </ItemGroup>
  <MakeDir Directories="$(WebProjectOutputDir)\bin\roslyn" />
  <Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)\bin\roslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" />
</Target>

其他回答

我在服务器上安装应用程序时遇到了同样的问题,而在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中的所有文件

这解决了我的问题。

默认的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>

我尝试了多个顶级答案,直到下面的步骤起作用(ASP。NET项目,目标是。NET Framework 4.6.2, Visual Studio 2019,在一个具有疯狂限制性组策略的系统上,2021年3月)。

我需要:

以管理员身份运行VS 在包管理器控制台运行 更新- package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -v 2.0.1 清洁和重建解决方案

如果不以Admin身份运行VS,组策略会阻塞Update-Package需要运行的ps1脚本。

PS.在此工作之前,我尝试了许多其他答案(并在他们失败后运行git reset)。我不知道他们中是否有人最终促成了这一切。我试着:

https://stackoverflow.com/a/32780433/4658148 https://stackoverflow.com/a/34391473/4658148 https://stackoverflow.com/a/41484473/4658148 https://stackoverflow.com/a/62136000/4658148 https://stackoverflow.com/a/54341249/4658148 https://stackoverflow.com/a/51308385/4658148

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文件夹并重新生成解决方案。这样问题就解决了