I have a NuGet package I'm writting to automatically update the year in a project's copyright. It works, but the problem is, the target seems to run when it's not supposed to. For example: The moment I add the NuGet package it will immediately run, thus causing Visual Studio to complain that the project file I just imported it into was modified.
I've noticed that if I change the copyright year before the build, somehow the target will run before the build and the year will have already been corrected by the time the target runs during the build.
How do I tell MSBuild targets to only run when the user requests a build?
Edit: Currently I'm testing this with a .NET Core project, but it should be able to work with Framework and Standard too.
File: build\TriggersTools.AssemblyCopyrightYear.targets
<!-- Modify the assembly's copyright year -->
<Project>
<PropertyGroup>
<TaskFolder Condition=" '$(MSBuildRuntimeType)' == 'Core' ">netstandard1.3</TaskFolder>
<TaskFolder Condition=" '$(MSBuildRuntimeType)' != 'Core' ">net46</TaskFolder>
<TaskAssembly>$(MSBuildThisFileDirectory)..\tasks\$(TaskFolder)\TriggersTools.AssemblyCopyrightYear.dll</TaskAssembly>
</PropertyGroup>
<UsingTask TaskName="TriggersTools.AssemblyCopyrightYear.CopyrightYear" AssemblyFile="$(TaskAssembly)"/>
<Target Name="TriggersToolsAssemblyCopyrightYearAssign" BeforeTargets="PrepareForBuild">
<!-- Run the CopyrightYear task -->
<CopyrightYear ProjectPath="$(MSBuildProjectFullPath)" />
</Target>
</Project>
File: buildMultiTargets\TriggersTools.AssemblyCopyrightYear.targets
<!-- Modify the assembly's copyright year -->
<Project>
<!-- Import the build .targets file since this one is no different -->
<Import Project="$(MSBuildThisFileDirectory)..\build\TriggersTools.AssemblyCopyrightYear.targets"/>
</Project>