visual studio – Hybrid javascript + C# project, copying to wwwroot


I have solution with many projects. One of those, let’s call it SPA, is a “plugin” in the form of a web application which inserts itself at runtime in the main loop of the main project let’s call it BASE.

I build BASE from Visual Studio. SPA is referenced by BASE, and is built as well.

I need to copy generated bundles and assets from SPA/wwwroot to BASE wwwroot.

I did the following in SPA .csproj in order to copy:

<Target Name="CopyToWwroot" BeforeTargets="Build">
    <!-- Collect all wwwroot files recursively -->
    <ItemGroup>
        <WwrootFiles Include="wwwroot/**/*" />
    </ItemGroup>
    <!-- Log each file being copied -->
    <Message
        Text="Copying %(WwrootFiles.Identity) to $(TargetDir)wwwroot\%(WwrootFiles.RecursiveDir)"
        Importance="High"
    />
    <!-- Perform the copy -->
    <Copy
        SourceFiles="@(WwrootFiles)"
        DestinationFolder="$(OutDir)wwwroot\%(RecursiveDir)"
        SkipUnchangedFiles="true"
    />
</Target>

Important (maybe): as it is a plugin, SPA is declared as Microsoft.NET.Sdk (not .web)

Problem: This csproj xml copies files to SPA build output wwwroot, not to BASE build output.

I tried with $TargetDir , same problem.

Before that I simply asked to copy SPA wwwroot files via Visual Studio properties “PreserveNewest” etc => it creates ItemGroup but in this case the files to copy seems to be evaluated very early and kept in cache or something, and my new React+Vue built files are not copied, only on the second build of BASE ! So I decided to copy more “manually” but now I have the output directory problem.

Leave a Reply

Your email address will not be published. Required fields are marked *