mark
mark

Reputation: 62876

Why is building two targets with msbuild different from building each target separately?

I have a project that imports a certain targets file from a Nuget package. Even though I use PackageReferences I am forced to import this file manually.

(See my other question for details - How are we supposed to execute package build targets in the new world where nuget packages are consumed through msbuild PackageReference?)

This targets file injects chromedriver.exe into the Content item group with CopyToOutputDirectory = PreserveNewest.

I observe a situation where chromedriver.exe is not copied to the bin folder when running msbuild /t:"Restore;Build", but it is copied when running the two targets separately - msbuild /t:Restore; msbuild /t:Build.

Can anyone explain how this happens?

(I killed a good portion of the day learning the difference on my skin, want to know how come?)

Upvotes: 2

Views: 398

Answers (1)

Martin Ullrich
Martin Ullrich

Reputation: 100751

Restore changes the imported project files in the obj\ directory.

For this to take effect, the project file needs to be re-evaluated entirely, which does not happen when you run the Restore and Build targets in the same invocation.

Use the -restore command line switch for MSBuild to run a Restore before the other specified targets in the same command line call. MSBuild will run the Restore, empty its XML caches and re-evaluate the project again when running the requested build.

Upvotes: 3

Related Questions