MSBuild : want to detect when files change for the target to be called
I am trying to write targets file that is imported by a project:
It doesn't call that target when i change the input files at all whatever i tried nothing. The way i know if it actually happend is by looking at that timestamp file Let me know if you need more context.
It doesn't call that target when i change the input files at all whatever i tried nothing. The way i know if it actually happend is by looking at that timestamp file Let me know if you need more context.
46 Replies
$(MSBuildProjectDirectory)/$(IntermediateOutputPath)
doesn't seem correct to me
that would result in D:\Projects\MyProj\src\MyProj\D:\Projects\MyProj\src\MyProj\obj
nope
IntermediateOutputPath
gave me relative pathinteresting, well if it works
i removed it tho
what's running
RunGenTool
?
why this in FenzworkSetup
and then again
in RunGenTool
?its leftover of when i wanted it to create file but it shouldn't serve any purpose yeh
is there anything that executes
RunGenTool
?Like CallTarget nope
Its like as you see
well then what would possibly run it...?
Inputs outputs ?
Yeah, there's nothing that's including the RunGenTool target in the targets graph. You probably need to add AfterTargets="FenzworkSetup" and BeforeTargets="BeforeBuild" to the RunGenTool target.
There are few ways a target will be run:
1) being listed in the Initial/DefaultsTargets property on a project.
2) being the first target in the project xml graph. (I don't think this would be smart to depend on).
3) being related to 1) or 2) by using DependsOnTargets, BeforeTargets, AfterTargets
4) explicitly invoking via the CallTarget task.
Your RunGenTool target doesn't satisfy any of those.
Or I guess 5) explicitly specifying the target as a command line parameter to msbuild/dotnet build. But, without before/afterTargets, there's nothing to indicate when your target should run.
Wait so inputs outputs don't call the target they work as conditions?
Correct. The target will still only be invoked if any of the inputs has a more recent modified date than any of the outputs.
does it detect deletion and creation of input files?
it doesn't seem to detect them
I assume that if an output file is missing, that would trigger the target to run. If an input is missing, I'd assume not. Creation would cause a newer modified date, so I'd expect that to behave normally. But, you have to fully list the inputs and outputs, so if your ourputs are non-deterministic, you might not be able to use the inputs/outputs mechanism.
Indeed, the inputs/outputs is really just an opitimization to avoid running targets/tasks that don't need to do anything. But, they should be idempotent, so running them even when not needed should only be a waste of time.
So it can follow the items existence in list ?
Like i use this but next call will the content stay the same or reincluded?
Like it works when modifying the file but not when deleting or creating a file
Sorry, I don't understand what you're asking.
AssetsFiles
if say has foo/bar;lorem.ipsum;something
if something
was deleted will it remain in the AssetsFiles
?Yes.
Though, it would be strange for an input file to be deleted during a build...
hmm i might misunderstood how msbuild work so when it wants to build it execute msbuild and all of the properties and items will not be saved across the executions is that how works ?
No, nothing is saved between executions.
The project is re-evaluated from scratch every time
ah i see
welp i want to detect when a file is created or deleted
that's my goal now
During the build?
i use CoreCompile
I don't know what you're trying to accomplish, so I'm not sure how to advise you.
which i don't know exactly when its called but it gets called behind the scene
If you need to run your code before or after core compile, just tell MSBuild that using the Before/AfterTargets. BeforeTargets="CoreCompile" will cause your target to be invoked before CoreCompile.\
i did but Inputs and Outputs don't seem to see the creation nor deletion of the files
creation or deletion of what files?
which i put in Inputs
The inputs/outputs should ideally be deterministic.
So, when you start your build all the assets files are the inputs. Why would assets be created/deleted during the build?
i use CoreCompile because it doesn't get called when building i ve heard its usefull to generate code from MSBuild so i used it
Yes, generating code from MSBuild is very useful. So, your trying to take assets files, turn them into .cs files, and have those .cs files included in the C# compilation?
yeh something like this
And you're having difficulty getting your Target that does the code gen to run?
Have you removed the Inputs/Outputs attributes? I'd remove those first. Like I said, treat those as an optimization after you get everything else working.
but i wanna make sure they work or else i will create real-time tool to do the job maybe
Make the Inputs/Outputs work after you make everything else work. They are an optimization only. If your process doesn't work, there's nothing to optimize.
Incremental builds in MSBuild - MSBuild
Explore the incremental build feature in MSBuild, which produces builds that are optimized so up-to-date output files aren't executed.
it works not that it doesn't
It works? Okay. What are we talking about then?
just need to know if thats worth the effort to make it to work once a file changed or created or removed with MSBuild or not
with out the Inputs/Outputs sorry if im confusing
So, maybe your Inputs/Outputs aren't what you think they are? Have you debugged the content of the Inputs/Outputs collection?
yes
wait
that's weird it called the target when i removed a file than it stoped doing that
the file you removed was an input or output file?
oh wait no it worked cause i removed inputs outputs
so the outputs is basically just a file that i
touch
when the target RunGenTool
is calledAnd you're finding that if you modify an input file (asset) then the target isn't running as you expect?