Quantcast
Channel: 黑暗執行緒
Viewing all articles
Browse latest Browse all 2311

神祕的ASP.NET bin\roslyn目錄

$
0
0

同事由TFS取回ASP.NET MVC專案,編譯後執行出現以下錯誤:

[DirectoryNotFoundException: 找不到路徑 'D:\TFS\src\web\MyForm\bin\roslyn\csc.exe' 的一部分。]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +353
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +1326
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +65
Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.get_CompilerName() +91
Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.FromFileBatch(CompilerParameters options, String[] fileNames) +656
Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.CompileAssemblyFromFileBatch(CompilerParameters options, String[] fileNames) +186
System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromFile(CompilerParameters options, String[] fileNames) +24
System.Web.Compilation.AssemblyBuilder.Compile() +950
System.Web.Compilation.BuildProvidersCompiler.PerformBuild() +10029581
System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +9979064
System.Web.Compilation.BuildManager.CompileGlobalAsax() +44
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +260

bin\roslyn\csc.exe?ASP.NET什麼時候冒出這玩意?印象裡又彷彿看過… 查了手上幾個ASP.NET專案的bin目錄,還真有個roslyn目錄,裡面有C#及VB的Compiler執行檔,還有一堆DLL:

追進csproj檔,有設定指向\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform、\packages\Microsoft.Net.Compilers…

<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" />

<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <HintPath>..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
  <Private>True</Private>
</Reference>

<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />

由此推測這是ASP.NET透過NuGet安裝,用於執行期間動態編譯程式碼的程式套件。使用NuGet管理員,驗證ASP.NET專案被安裝了Microsoft.CodeDom.Providers.DotNetCompilerPlatform,而Microsoft.NetCompilers是其依賴的底層套件。套件說明提到,ASP.NET傳統是用CodeDOM解決執行期間動態編譯需求,新版ASP.NET已改用新世代的.NET編譯平台(Roslyn)。

Roslyn是2014推出的新一代Open Source編譯平台,Visual Studio 2015起改用Roslyn作為編譯核心,ASP.NET專案樣版也開始改用Roslyn處理MVC View、WebForm Inline Code動態編譯,這就是bin/roslyn目錄的由來。

回到最初的問題,為什麼同事從TFS取回我的ASP.NET專案編譯會缺少Roslyn套件呢?

老問題!.csproj搬過家,由Sln/Blah.csproj搬到Sln/Web/Blah.csproj,還記得之前遇過的..\packages改..\..\packages NuGet HintPath問題嗎?csproj裡Roslyn CodeDOM設定仍指向..\packages,搬家後需手動修改。

問題在修改路徑修後排除,結案。


Viewing all articles
Browse latest Browse all 2311

Trending Articles