前言
事情發生在 clone 專案編譯執行後發生的。以前曾經也發生過,但不記錄還是會忘了解法,趁現在遇到了,快記一下!
問題
ASP.NET MVC 專案在 git clone 下來編譯後執行網站出現:System.IO.DirectoryNotFoundException: 找不到路徑 'bin\roslyn\csc.exe' 的一部分
解決方法
開啟專案 *.csproj
檔,加上 Target 的 AfterTargets 設定
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |