Skip to content

uSync files default to Content CopyIfNewer. Change to "only for publish". #833

@lars-erik

Description

@lars-erik

Is your feature request related to a problem? Please describe.

When there is a large amount of uSync files, like thousands of content items, the build time of projects increase by an order of magnitude. It is totally unnecessary to copy the uSync files to the output folders of regular builds. Not to mention the effect being transitive for dependent projects like integration tests.

I just shaved 90 seconds off a solution build (Only 30 sec now) by only allowing copying the uSync files on publish.

Describe the solution you'd like

Prevent uSync from copying files unless the web project is being published, while allowing consumers to override the behavior.

Describe alternatives you've considered

Add a .targets file in the uSync package that prevents copying on regular builds.

For instance:

uSync.targets:

<Project>

  <PropertyGroup>
    <!-- Allow users to disable the default uSync publish behavior -->
    <EnableUSyncPublishDefaults Condition="'$(EnableUSyncPublishDefaults)' == ''">true</EnableUSyncPublishDefaults>
  </PropertyGroup>

  <ItemGroup Condition="'$(EnableUSyncPublishDefaults)' == 'true'">
    <Content Remove="uSync/**"/>
  </ItemGroup>

  <Target Name="CollectUSyncFilesForPublish" BeforeTargets="AddUSyncFilesToPublishedItems" Condition="'$(EnableUSyncPublishDefaults)' == 'true'">
    <Message Text="Collecting the initial files" Importance="High"/>

    <ItemGroup>
      <USyncFilesToCopy Include="uSync/**" />
    </ItemGroup>
  </Target>

  <Target Name="AddUSyncFilesToPublishedItems" BeforeTargets="GetCopyToPublishDirectoryItems" Condition="'$(EnableUSyncPublishDefaults)' == 'true'">
    <Message Text="Adding the files we've collected to the ContentWithTargetPath group" Importance="High"/>
    <ItemGroup>
      <ContentWithTargetPath Include="@(USyncFilesToCopy)" TargetPath="%(Identity)" CopyToOutputDirectory="Never" CopyToPublishDirectory="Always" />
    </ItemGroup>
  </Target>

</Project>

Consumer .csproj:

<Target Name="RemoveUSyncFilesWeDontWant"
        AfterTargets="CollectUSyncFilesForPublish"
        BeforeTargets="AddUSyncFilesToPublishedItems"
        Condition="'$(EnableUSyncPublishDefaults)' == 'true'"
        >
  <Message Text="Removing the files we don't want" Importance="High"/>
  <ItemGroup>
    <USyncFilesToCopy Remove="uSync/v*/Content*/**" />
    <USyncFilesToCopy Remove="uSync/v*/Media*/**" />
  </ItemGroup>
</Target>

The above targets have been tested in a single .csproj, but should work fine if put in a buildTransient/uSync.targets file in the package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions