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

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

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

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

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


当前回答

为了防止构建也将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')" /> -->

其他回答

为了防止构建也将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')" /> -->

在我的例子中,类似于Basim,有一个NuGet包告诉编译器我们需要c# 6,而我们并不需要。

我们必须删除NuGet包Microsoft.CodeDom.Providers.DotNetCompilerPlatform,然后删除:

<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net452" /> from the packages.config file <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /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.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" /> </compilers> </system.codedom>

在系统中。codedom节点,你可以看到为什么它带来roslyn: compilerOptions="/langversion:6

在我的情况下,我们的团队不想保留“包”文件夹,所以我们把所有的dll放在其他目录,如“sharedlib”。

我使用构建事件来解决这个问题。

if "$(ConfigurationName)" == "Release" (
goto :release
) else (
goto:exit
)

:release
if not exist $(TargetDir)\roslyn mkdir $(TargetDir)\roslyn

copy /Y "$(ProjectDir)..\..\Shared Lib\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\tools\Roslyn45\*" "$(TargetDir)\roslyn"
goto :exit

:exit

清洁解决方案 重建方案 这两步对我很管用。

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