問題描述
為什麼我的項目在沒有變化的情況下構建? (Why do my projects build when there are no changes?)
我有許多 C# (Visual Studio 2008) 項目,其中一些正在更新程序集,即使沒有任何更改(即使我選擇了構建而不是重新構建)。我的大多數項目都沒有這樣做,只是少數幾個。
我還沒有發現項目之間的任何差異,並想知道是否有人知道是什麼影響了它。需要明確的是,我在構建之前沒有對代碼進行任何更改,但是當我在 Visual Studio 中運行 Build 命令時,仍然會重新創建程序集。
很抱歉,我無法提供更多詳細信息但請讓我知道是否還有其他可以檢查的信息。
有人可以幫忙嗎?我已經為此煩惱了一段時間。
謝謝,艾倫
參考解法
方法 1:
Actually Hans' now‑deleted answer pointed me to the right direction. Cranking up MSBuild's verbosity to diagnostic told me that VS considered a project always out of date because one file had "Copy to output directory" set to "Copy always". And the other projects followed from that because they depended on that project an noticed that the newly‑built DLL was newer than one of their own output files.
Changing "Copy to output directory" to "Copy if newer" resolved that.
方法 2:
There is something called project dependencies.
When one of your project depends on one or more other projects and you build it the other projects that your projects depends on will also begin to be built (if needed). Additionally if the dependencies have changed then the projects dependent on them will always be rebuilt.
You can Right Click on Solution and select Project Build Order to bring up a window which explains the order in which projects are built and the dependencies for each project.
方法 3:
I didn't get to the bottom of this one and ended up reconstructing one of the projects. It turned out that it was all stemming from this one project that was always rebuilding.
I think it had something to do with the embedded resources being rebuilt every time.
Sorry I don't have a definitive answer on this one. Thanks to RobV too for the useful information.
Alan
(by Alan Spark、Joey、user415789、Alan Spark)