Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Broken Build]: Native DLL output deleted on IncrementalClean #10931

Open
znakeeye opened this issue Nov 4, 2024 · 8 comments
Open

[Broken Build]: Native DLL output deleted on IncrementalClean #10931

znakeeye opened this issue Nov 4, 2024 · 8 comments
Assignees
Labels

Comments

@znakeeye
Copy link

znakeeye commented Nov 4, 2024

Issue Description

I have a WPF exe project referencing a Library project which in turn references a Native DLL project. See attached sample project.

When rebuilding the solution, the output folder of the exe project contains all binaries:

MyLib.dll
NativeLib.dll
WpfApp2.dll
WpfApp2.exe

Then, perform any code change in the WpfApp2 project and Build it (F7 on my setup). The NativeLib.dll gets deleted. Using verbose logging, I can see that it incorrectly gets picked up in _CleanOrphanFileWritesInOutput processed by the IncrementalClean target.

Steps to Reproduce

See attached sample project.

SimpleApp.zip

Expected Behavior

Native DLL output should not be deleted when building solution.

Actual Behavior

Native DLL output is deleted when building solution.

In real-world solutions, this causes runtime errors. We have spent many days trying to debug issues that weren't real issues; the build is in fact broken.

Ask us questions

No response

@JaynieBai JaynieBai self-assigned this Nov 6, 2024
@JaynieBai
Copy link
Member

Repro it and binlog msbuild.binlog.txt

@yuehuang010
Copy link
Contributor

Generally, the task/target that copies the NativeLib.dll to the output directory should also append to the "FileWrite" ItemGroup so that the Incremental Clean step won't delete it.

I wonder if this is the bug where building from the IDE and command line has different behavior.

@KalleOlaviNiemitalo
Copy link

It's "FileWrites", plural.

Which is not consistent with item types like "Compile" having been named with the singular form, but too late to change now.

@jzabroski
Copy link

jzabroski commented Nov 25, 2024

Note, this is not necessarily the same issue as the one linked above just now.

In this issue, the problem is a Native DLL project.

In my issue, the problem is with nuget package Microsoft.Data.SqlClient.SNI copying Native DLLs from its buildTransitive folder to the build output directory, but subsequently gets deleted by IncrementalClean.

If a member of the nuget team can explain how does nuget normally handle this, I can try to pitch in and fix this. I tried to find the nuget targets that control restore but no success yet. I plan to search everywhere FileWrites is mentioned in my sdk path.

It does seem like there should be a simple item collection that automatically gets added to FileWrites by the Build step, or similar. As a simple thought, the item collection could be called <Runtimes> as we have a <Content> folder already that maps to the nupkg top-level folder \content\. Perhaps this already exists in some other form and I'm simply unaware.

@YuliiaKovalova
Copy link
Member

Just to share on my progress on this topic and hopefully hear from you on possible ideas.

For the similarities between first and second build:
Image
Image

Ideally, based on _IsNativeEnvironment property presence, I would add it either to FieWrites or exclude from collection in InrementalClean.
I managed to add C:\Users\ykovalova\Downloads\SimpleApp\SimpleApp\x64\Debug\NativeLib.dll to FileWrites since it's visible in scope of GetCopyToOutputDirectoryItems execution, but I need preserve this path: \WpfApp2\bin\Debug\net6.0-windows\NativeLib.dll , that isn't available when I need it (inside of MSBuild task execution).

Now I am thinking about the ways on either passing \WpfApp2\bin\Debug\net6.0-windows to GetCopyToOutputDirectoryItems target or saving all project info with _IsNativeEnvironment =true and handle it in IncrementalClean.

@yuehuang010
Copy link
Contributor

This looks similar to #9841. As a difference between IDE and cmd line when resolving outputs from the Project Reference. In the IDE, it calls GetTargetsPath target while the cmd line calls Build target. The GetTargetsPath target returns Returns="$(TargetPath)" which includes both managed and native. The Build target returns @(ManagedTargetPath) managed only, in this case, empty.

A simple change to Build target in Microsoft Visual Studio\2022\Preview\MSBuild\Microsoft\VC\v170\Microsoft.BuildSteps.Targets to Returns="$(TargetPath)" to return NativeLib.dll. But there might unforeseen consequences.

@YuliiaKovalova
Copy link
Member

As a temproary workaround, I would suggest neutering the in the box <Target Name="IncrementalClean" /> by putting the empty target to yours Directory.Build.targets .

@fforjan
Copy link

fforjan commented Dec 16, 2024

@YuliiaKovalova I tried with the workaround and this does not solve the visual studio build (but seems to solve the one in command line) (from issue #9841 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants