zoukankan      html  css  js  c++  java
  • codedom roslyn compilation error

    项目是.net4.7.2的,

    codedom的nuget包下面

    Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1 ools有3个子文件夹

    net45文件夹是安装和卸载的脚本

    Roslyn45是4.5的版本,不支持高级语法

    RoslynLatest是最新的版本,支持高级语法

    之前手动复制了Roslyn45,出现编译错误,因为不支持C#的新语法

    Could not find a part of the path … bin oslyncsc.exe

    回答1

    The problem with the default VS2015 templates is that the compiler isn't actually copied to the tfrin oslyn directory, but rather the {outdir} oslyn directory

    Add this code in your .csproj file:

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

    回答2

    TL; DR

    run this in the Package Manager Console:   参数r应该是reinstall的意思

    Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r

    Update-Package -reinstall Microsoft.CodeDom.Providers.DotNetCompilerPlatform

    More information

    This problem is not related to Visual Studio itself, so answers suggesting adding build steps to copy files over are rather a workaround. Same with adding compiler binaries manually to the project.

    The Roslyn compiler comes from a NuGet package and there is/was a bug in some versions of that package (I don't know exactly which ones). The solution is to reinstall/upgrade that package to a bug-free version. Originally before I wrote the answer back in 2015 I fixed it by installing following packages at specific versions:

    • Microsoft.Net.Compilers 1.1.1
    • Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.1

    Then I looked into .csproj and made sure that the paths to packages are correct (in my case ....packages*.*) inside tags <ImportProject> on top and in <Target> with name "EnsureNuGetPackageBuildImports" on the bottom. This is on MVC 5 and .NET Framework 4.5.2.

  • 相关阅读:
    GITHUB随笔 15-5月 junit
    github心得
    (转)哪个瞬间让你突然觉得逛知乎真有用?
    0-1背包问题(the knapsack problem)
    对VSCode在安装了Dev-cpp的电脑上的配置
    非全日制考研资料(未完待续)
    CSS那些事读书笔记-2
    CSS那些事读书笔记-1
    前端面试准备-1
    工作日记-一个有趣的定时任务实现
  • 原文地址:https://www.cnblogs.com/chucklu/p/13851064.html
Copyright © 2011-2022 走看看