0
votes

I have an external project with a multitude of "common" javascript/etc content files to be shared across multiple web projects. Using the new LinkBase property in my csproj file, along with a combination of the trick here: http://mattperdeck.com/post/Copying-linked-content-files-at-each-build-using-MSBuild.aspx I now have the exact hierarchy of the linked project copied to the main project, and when I run my website the content files function and are found, and the bundling is even happening correct, which is great!

Issue is, after one closes the application, the copied content files remain behind, and since its a team project, it could become confusing for other devs which files are the "master" copies and which are the copied, there's no visual indicator for this.

Is there a way I can do one of the two following?

A: During the copy task, prepend all files with some commented text indicating something like "This was copied from the Linked Project, dont edit this file, all changes will be lost, go edit the file over here ->"

Or:

B: Is there a way I can delete the files once the project is closed? I'm not seeing any build events that happen after the project completes so I am guessing this option is likely not possible.

Here's what I currently have, which is pretty straightforward:

<ItemGroup>
  <Content Include="..\MyFileLinks\**\*.js" LinkBase="" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
  <Copy SourceFiles="%(Content.Identity)"
        DestinationFiles="%(Content.Link)"
        SkipUnchangedFiles='true'
        OverwriteReadOnlyFiles='true'
        Condition="'%(Content.Link)' != ''" />
</Target>
1
you can add files to your project As Link. Then, in the properties, set it as content, and set Copy Always. The file itself will always be in the folder it resides. The copy of the file will be copied into the output.T.S.
That doesnt answer my question unfortunately. That is already what I have happening.Steffen Cole Blake
@SteffenColeBlake, any update about this issue? Please let us know if my answer helps you handle the issue or not.Mr Qian

1 Answers

0
votes

The best way is to add a delete target that depends on Clean process. And actually, there is no target that relys on close vs because any targets depend on the build process rather than close VS or open VS.

So my suggestion is to add a target that relys on clean process to delete those files.

Add this target:

<Target Name="RemoveFiles" AfterTargets="Clean">
        <Message Importance="high" Text="%(Content.Link)"></Message>
        <Delete Files="%(Content.Link)"></Delete>
</Target>

Before you want to close VS, please click Clean, the files will be removed at that time.