Project always rebuilt: Improper up-to-date check with conditional items
See original GitHub issueThis issue has a corresponding ticket on Developer Community. Please vote and comment there to make sure your voice is heard.
- Create a new project (I used C# UWP app, this bug may be in other project types).
- Add a content file (for example,
dummy.xml
) - Change the file to “Copy if newer”
- Save the solution
- Open the project file in a text editor (e.g. by unloading the project and selecting Edit from the context menu)
- Find the content file and add a condition that always fails. For example, change this:
<Content Include="dummy.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
to this:
<Content Include="dummy.xml" Condition="'Foo' == 'Bar'">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
- Reload the project
- Build
- Build again
(The attached project contains this repro).
Expected: In step 9, the project should not be rebuilt since everything is up to date.
Actual: The project is rebuilt. In the output window we see the following trace:
1>Project ‘VSBug7’ is not up to date. Copy to output file ‘c:\prj\VSBug7\bin\x86\Debug\dummy.xml’ missing from output location. This is incorrect, since
dummy.xml
was excluded due to the condition.
Additional notes:
Although the repro steps in this bug use a condition that always fails, this is only for illustration purposes. I found this bug with a more sane condition (Condition="'$(Platform)' == 'x64'"
) which is sometimes true and sometimes false. The point is that when the condition is false the dependency is not properly ignored in the up-to-date check.
Original Comments
Oz Solomon [MSFT] on 3/12/2020, 07:34 AM:
I'll also add that this problem occurs if the condition is placed on the `ItemGroup` rather than the item.
Visual Studio Feedback System on 3/12/2020, 07:14 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Sara Liu [MSFT] on 3/17/2020, 01:03 AM:
Thank you for your feedback and taking the time to reach out to us. I can reproduced this issue through your shared steps and this issue has been escalated for further investigation, if there is any process, I will inform you immediately.
Maik Gerth on 6/18/2020, 03:36 AM:
I have the same problem when we copy .dlls conditionally based on the Platform in C#, example from .csproj:
<Content Include="…\DLL\testx32dbg.dll" Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<Link>testx32dbg.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="…\DLL\testx64.dll" Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<Link>testx64.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Then Visual Studio Diagnostic Build will always trigger a rebuild, because it thinks that one of the .dlls (from the irrelvant Platform for the current build which it therefore did not copy) is missing e.g. in 32bit Debug it would show
Project 'MyProject' is not up to date. Copy to output file '…Debug32\textx64.dll' missing from output location.
Original Solutions
(no solutions)
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
For all readers who wonder what this is about, see https://github.com/dotnet/project-system/blob/master/docs/opening-with-new-project-system.md
@mgexo there are two main C# project systems that ship with VS.
So to answer your question, the new project system was available back in July when this issue was closed.