I'm referencing this article in an attempt to copy linked files before each build:
<Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
<Copy SourceFiles="%(Content.Identity)"
DestinationFiles="%(Content.Link)"
SkipUnchangedFiles='true'
OverwriteReadOnlyFiles='true'
Condition="'%(Content.Link)' != ''" />
</Target>
This doesn't appear to work for the new .NET Core csproj tooling. What would be an equivalent target that does?
EDIT: Example csproj content
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Features>IOperation</Features>
<Configurations>Debug;Release;Template</Configurations>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\MyRefProject\ChangeTypes.cs" Link="ChangeTypes.cs" />
<Compile Include="..\MyRefProject\Parser.cs" Link="Parser.cs" />
<Compile Include="..\MyRefProject\Calculator.cs" Link="Calculator.cs" />
<Compile Include="..\MyRefProject\Converter.cs" Link="Converter.cs" />
</ItemGroup>
</Project>
A Condition should be specified at the Target level but this won't help in this scenario because you can't use an elements metadata as a condition.
You also need to provide an output path. Your example will only copy linked content into the project's directory, not it's output directory.
<Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
<Copy SourceFiles="%(Content.Identity)"
DestinationFiles="$(OutputPath)\%(Content.Link)"
SkipUnchangedFiles="true"
OverwriteReadOnlyFiles="true" />
</Target>
The documentation for the Copy task can be found here.
I tested this using Visual Studio 2017 with two simple console projects. The second project included a couple of text files. The first project also references these files via content links. This is the .csproj file from the first project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Content Include="..\Project2\ReadMeFirst.txt" Link="ReadMeFirst.txt" />
<Content Include="..\Project2\ReadMeSecond.txt" Link="ReadMeSecond.txt" />
</ItemGroup>
<Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
<Copy SourceFiles="%(Content.Identity)"
DestinationFiles="$(OutputPath)\%(Content.Link)"
SkipUnchangedFiles="true"
OverwriteReadOnlyFiles="true" />
</Target>
</Project>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With