Skip to content

Latest commit

 

History

History

NoTargets

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Microsoft.Build.NoTargets

NuGet NuGet

The Microsoft.Build.NoTargets MSBuild project SDK allows project tree owners the ability to define projects that do not compile an assembly. This can be useful for utility projects that just copy files, build packages, or any other function where an assembly is not compiled.

Example

To have a project that just copies a file:

<Project Sdk="Microsoft.Build.NoTargets">

  <PropertyGroup>
    <TargetFramework>net46</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <FilesToCopy Include="files\**" />
  </ItemGroup>

  <Target Name="CopyFiles" BeforeTargets="PrepareForRun">
    <Copy
        SourceFiles="@(FilesToCopy)"
        DestinationFolder="$(OutDir)"
        SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
        OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
        Retries="$(CopyRetryCount)"
        RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
        UseHardlinksIfPossible="$(CreateHardLinksForCopyAdditionalFilesIfPossible)"
        UseSymboliclinksIfPossible="$(CreateSymbolicLinksForCopyAdditionalFilesIfPossible)">
      <Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
    </Copy>
  </Target>
</Project>

Note: to leverage build incrementalism through FileWrites, ensure the custom target runs BeforeTargets="PrepareForRun" as above.

Or a project that runs a tool:

<Project Sdk="Microsoft.Build.NoTargets">
  <PropertyGroup>
    <TargetFramework>net46</TargetFramework>
    <MyTool>mytool.exe</MyTool>
  </PropertyGroup>

  <Target Name="RunTool" BeforeTargets="AfterBuild">
    <Exec Command="$(MyTool) -arg1 value" />
  </Target>
</Project>

Extensibility

Setting the following properties control how NoTargets works.

Property Description
CustomBeforeNoTargetsProps A list of custom MSBuild projects to import before NoTargets properties are declared.
CustomAfterNoTargetsProps A list of custom MSBuild projects to import after NoTargets properties are declared.
CustomBeforeNoTargets A list of custom MSBuild projects to import before NoTargets targets are declared.
CustomAfterNoTargets A list of custom MSBuild projects to import after NoTargets targets are declared.

Example

Add to the list of custom files to import after NoTargets targets. This can be useful if you want to extend or override an existing target for you specific needs.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <CustomAfterNoTargets>$(CustomAfterNoTargets);My.After.NoTargets.targets</CustomAfterNoTargets>
  </PropertyGroup>
</Project>