C#C
C#7mo ago
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>

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.
Was this page helpful?