0

I have a .target file, which imports to my project:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="CreateInstaller">    
  <Import Project="$(PathToTargetFile)\My.target" />
<Project>

The .target is build by another target:

  <Target Name="MyCustomTarget" DependsOnTargets="$(OtherTargets)">
    <MSBuild Projects="$(PathToTargetFile)\My.target" />
  </Target>

The target MyCustomTarget is called several time, each time the content of My.target would be changed. But My.target seems that not imported anymore rather than the first time. How to resolve this problem?

1 Answers1

0

How to resolve this problem?

Visual Studio caches all imported .target files. That is the reason why you My.target seems that not imported anymore rather than the first time.

To resolve this issue, you can use a temp .target file with different name, this will force VS to reload .target file:

  <Target Name="AfterBuild">
    <PropertyGroup>
      <TempProjectFile>My.$([System.Guid]::NewGuid()).target</TempProjectFile>
    </PropertyGroup>
    <Copy SourceFiles="My.target" DestinationFiles="$(TempProjectFile)" />
    <MSBuild Projects="$(TempProjectFile)" />
    <Delete Files="@(TempProjectFile)" />
  </Target>

You can refer to the similar issue for detail info.

Hope this help you.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135