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>
As Link
. Then, in the properties, set it ascontent
, and setCopy 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.