© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•8mo ago•
62 replies
Fenz

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:

    <ItemGroup> 
        <AssetFiles 
                Include="$(AssetsFullPath)/**/*"
                Exclude="$(AssetsFullPath)/bin/*/**;$(AssetsFullPath)/obj/**/*;$(AssetsFullPath)/$(MGCBFileName)"/>
        <AssetsDirItem 
                Include="$(AssetsFullPath)"/>

    </ItemGroup>    
  <Target Name="FenzworkSetup" BeforeTargets="CoreCompile;BeforeBuild">
        
        <PropertyGroup><AssetsTimestampFilePath>$(MSBuildProjectDirectory)/$(IntermediateOutputPath)assets_timestamp.cache</AssetsTimestampFilePath>
        </PropertyGroup>

        <ItemGroup>
            <AssetsTimestamp Include="$(AssetsTimestampFilePath)"/>
        </ItemGroup>
        
        <Touch  Condition="!Exists($(AssetsTimestampFilePath))"
                Files="$(AssetsTimestampFilePath)"
                AlwaysCreate="True"/>

    </Target>
...
    <Target Name="RunGenTool"
        Inputs="@(AssetFiles)"
        Outputs="@(AssetsTimestamp)">
    
        <Message Text="Running GenTool..." Importance="High" />
    
        <Touch Files="@(AssetsTimestamp)" AlwaysCreate="true" />

        <Exec Condition="$(IsUsingSourceGenTool)"
              Command="dotnet &quot;$(GenToolDllPath)&quot; build &quot;%(AssetsConfig.Identity)&quot; &quot;%(AssetsDirItem.Identity)&quot; &quot;$(IntermediateOutputPath)&quot;" />
    </Target>
    <ItemGroup> 
        <AssetFiles 
                Include="$(AssetsFullPath)/**/*"
                Exclude="$(AssetsFullPath)/bin/*/**;$(AssetsFullPath)/obj/**/*;$(AssetsFullPath)/$(MGCBFileName)"/>
        <AssetsDirItem 
                Include="$(AssetsFullPath)"/>

    </ItemGroup>    
  <Target Name="FenzworkSetup" BeforeTargets="CoreCompile;BeforeBuild">
        
        <PropertyGroup><AssetsTimestampFilePath>$(MSBuildProjectDirectory)/$(IntermediateOutputPath)assets_timestamp.cache</AssetsTimestampFilePath>
        </PropertyGroup>

        <ItemGroup>
            <AssetsTimestamp Include="$(AssetsTimestampFilePath)"/>
        </ItemGroup>
        
        <Touch  Condition="!Exists($(AssetsTimestampFilePath))"
                Files="$(AssetsTimestampFilePath)"
                AlwaysCreate="True"/>

    </Target>
...
    <Target Name="RunGenTool"
        Inputs="@(AssetFiles)"
        Outputs="@(AssetsTimestamp)">
    
        <Message Text="Running GenTool..." Importance="High" />
    
        <Touch Files="@(AssetsTimestamp)" AlwaysCreate="true" />

        <Exec Condition="$(IsUsingSourceGenTool)"
              Command="dotnet &quot;$(GenToolDllPath)&quot; build &quot;%(AssetsConfig.Identity)&quot; &quot;%(AssetsDirItem.Identity)&quot; &quot;$(IntermediateOutputPath)&quot;" />
    </Target>

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.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

MSBuild doesn't detect files created using Target
C#CC# / help
2y ago
Run msbuild target only during dotnet pack
C#CC# / help
4y ago
✅ How can i change the target Framework?
C#CC# / help
4y ago
Create MSBuild custom task to modify C# files before compilation
C#CC# / help
10mo ago