0

I have a CS project that depends on some archive files and I have created MSBuild targets to build them. I cannot, however, get MSBuild to build these targets if project's files are up to date.

I have tried referencing the archive targets in the following places:

  • The project's before and after build targets
  • The project's InitialTarget and DefaultTarget attributes
  • In a separate targets file, which I tried to add as a project reference to my project. I'm not sure I used the item correctly though.

When I build, Visual Studio tells me that my project is up to date and does nothing. How can I make it consider my other targets as dependencies?

  • If you use the `` way to call targets, vs won't consider the project is up-to-date if there's any change in the xx.targets file, but if you have several targets you want to execute anyway no matter if the project is up-to-date, rebuild the project instead of build can be more suitable. – LoLance Aug 06 '19 at 09:06

1 Answers1

0

It seems that you build the project in VS IDE. VS IDE has a up-to-date check, if the project's output files are up-to-date with respect to their corresponding input files, it won't start build process.

I cannot, however, get MSBuild to build these targets if project's files are up to date.

Check this thread, if the input source files and output assemblies are corresponding up-to-date, VS won't really build and won't call your custom targets.

And according to your description, what you want is to run your target no matter if project file is up-to-date, I'm not sure what you mean make it consider my other targets as dependencies.What you really want is to run the custom targets anyway, if so, you can build the project by command-line or try rebuild instead of build button in VS. If I misunderstand anything, please feel free to let me know.

LoLance
  • 25,666
  • 1
  • 39
  • 73
  • The VS behavior is what I feared, but I couldn't find anywhere online to confirm it. I don't understand why VS would do this when MSBuild supports [incremental builds](https://learn.microsoft.com/en-us/visualstudio/msbuild/incremental-builds?view=vs-2019). Regarding my quote about making my other targets dependencies, I know that VS will build a project if a project which it references is out of date, even if that project's source files have not changed. I would like to accomplish that behavior with my custom target. – Chris Thomas Aug 06 '19 at 14:48
  • @ChrisThomas When calling msbuild.exe in VS IDE, there's one up-to-date check process before calling the msbuild I think. And the Incremental builds is something used to determine if we need to skip one target, when vs consider the project isup-to-date, it won't even execute any target in project file. Maybe you can try building the project in command-line, it seems the behavior you want(Incremental builds) can be accomplished in command-line. – LoLance Aug 06 '19 at 16:51