C
C#2w ago
Infi

Csproj Content Include Behaviour

So i have a setup that requires me to build my C# project after a nodejs project has been built, i managed to get that done using
<Target Name="NodeJS Compile" BeforeTargets="BeforeCompile">
<Exec Command="npm install" WorkingDirectory="Http\Frontend"/>
<Exec Command="npm run build" WorkingDirectory="Http\Frontend"/>
</Target>
<Target Name="NodeJS Compile" BeforeTargets="BeforeCompile">
<Exec Command="npm install" WorkingDirectory="Http\Frontend"/>
<Exec Command="npm run build" WorkingDirectory="Http\Frontend"/>
</Target>
The resulting files from svelte are placed inside a "build" directory and need to be shipped with the C# project finally, but <Content Include="Http\Frontend\build\**"> does take its file-list before the compile occured so it tries to copy older files Going with a
<Target Name="BeforeBuild" AfterTargets="Build">
<ItemGroup>
<Content Include="Http\Frontend\build\**">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Target>
<Target Name="BeforeBuild" AfterTargets="Build">
<ItemGroup>
<Content Include="Http\Frontend\build\**">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Target>
just copies nothing at all ... Any idea how i can fix this?
1 Reply
Infi
InfiOP5d ago
<Target Name="NodeJS Compile" BeforeTargets="BeforeCompile">
<Exec Command="npm install" WorkingDirectory="Http\Frontend"/>
<Exec Command="npm run build" WorkingDirectory="Http\Frontend"/>
</Target>

<Target Name="CopyFiles" AfterTargets="Build">
<ItemGroup>
<Files Include="$(MSBuildThisFileDirectory)\Http\Frontend\build\**" />
</ItemGroup>

<Copy SourceFiles="@(Files)" DestinationFolder="$(TargetDir)\Frontend\%(RecursiveDir)" />
</Target>
<Target Name="NodeJS Compile" BeforeTargets="BeforeCompile">
<Exec Command="npm install" WorkingDirectory="Http\Frontend"/>
<Exec Command="npm run build" WorkingDirectory="Http\Frontend"/>
</Target>

<Target Name="CopyFiles" AfterTargets="Build">
<ItemGroup>
<Files Include="$(MSBuildThisFileDirectory)\Http\Frontend\build\**" />
</ItemGroup>

<Copy SourceFiles="@(Files)" DestinationFolder="$(TargetDir)\Frontend\%(RecursiveDir)" />
</Target>
This seems to work ... This all runs through an automated pipeline that is completely automated, so the install is required to fetch the packages on each new run And no sadly not, the content is evaluated the moment the target is called, so again before execs are processed That's what I tested in the first attempt of fixing it That woukd work yes :Ok:

Did you find this page helpful?