專案分離後,Controllers 專案中的 Scaffold 功能創建的 View 文件留在錯誤位置,且「轉到視圖」導航失效。
<Link> 元素<!-- MyMvc.Controllers.csproj -->
<ItemGroup>
<Content Include="..\MyMvc.Web\Views\Home\Index.aspx">
<Link>Views\Home\Index.aspx</Link>
</Content>
</ItemGroup>
<Link> 在 VS 中表現為「快捷方式」:文件物理位於 Web 專案,但在 Controllers 專案中可見、可雙擊打開、不參與編譯。

// FileSystemWatcher 監控 Controllers 專案 Views 目錄
watcher.Created += (s, e) => {
if (e.FullPath.EndsWith(".aspx") || e.FullPath.EndsWith(".ascx")) {
// 1. 移動文件到 Web 專案對應目錄
File.Move(e.FullPath, webProjectPath + relativePath);
// 2. 更新 Controllers.csproj:移除舊項,添加 Link 項
UpdateCsprojLink(relativePath);
// 3. 刷新 VS 專案系統
DTE.ExecuteCommand("Project.Refresh");
}
};