How to add static assets for Blazor in a MSBuild Target #68108
|
If I include a file into For example, if I want to include the document of references, I need to use Task to add them. If I include them into <Target Name="GetFrameworkXmlDocumentation" AfterTargets="ResolveReferences">
<ItemGroup>
<Content Include="@(Reference->'%(RootDir)%(Directory)%(Filename).xml')" Condition="Exists('%(RootDir)%(Directory)%(Filename).xml')" />
</ItemGroup>
</Target>So that I need to use Copy to copy them: <Target Name="GetFrameworkXmlDocumentation" AfterTargets="ResolveReferences">
<ItemGroup>
<OutputDocuments Include="@(Reference->'%(RootDir)%(Directory)%(Filename).xml')" Condition="Exists('%(RootDir)%(Directory)%(Filename).xml')" />
</ItemGroup>
</Target>
<Target Name="CopyDocumentationsToOutputDirectory" AfterTargets="CopyFilesToOutputDirectory" DependsOnTargets="GetFrameworkXmlDocumentation">
<Copy SourceFiles="@(OutputDocuments)" DestinationFolder="$(OutputPath)wwwroot\_framework" />
</Target>
<Target Name="CopyDocumentationsToPublishDirectory" AfterTargets="CopyFilesToPublishDirectory" DependsOnTargets="GetFrameworkXmlDocumentation">
<Copy SourceFiles="@(OutputDocuments)" DestinationFolder="$(PublishDir)wwwroot\_framework" />
</Target>But the files will not record to the config of |
Replies: 14 comments 15 replies
|
Adding files to the Instead of dynamically adding
Could you clarify:
That information will help determine the correct extension point in the build pipeline. |
|
<Project Sdk="Microsoft.NET.Sdk.Web">
<Target Name="NpmBuild"
BeforeTargets="AssignTargetPaths">
<Exec Command="npm install"
WorkingDirectory="Site"
Condition="'$(RunNPMCompilation)' == 'true'" />
<Exec Command="npm run build -- $(NPMArguments)"
WorkingDirectory="Site"
Condition="'$(RunNPMCompilation)' == 'true'" />
<ItemGroup>
<Content Include="wwwroot\assets\**\*"
CopyToOutputDirectory="PreserveNewest"
CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
</Target>
</Project>
If you're generating files directly into wwwroot
<Target Name="NpmBuild"
BeforeTargets="AssignTargetPaths">
<Exec Command="npm run build -- $(NPMArguments)"
WorkingDirectory="Site"
Condition="'$(RunNPMCompilation)' == 'true'" />
</Target>
…On Sun, 2 Aug 2026 at 10:06, where where ***@***.***> wrote:
This also not working. Dose before PreBuildEvent still too late?
<Target Name="NPMBuild" BeforeTargets="PreBuildEvent">
<Exec Command="npm run build -- $(NPMArguments)" WorkingDirectory="Site" Condition="$(RunNPMCompilation)" />
<ItemGroup>
<Content Include="wwwroot/assets/**/*" />
</ItemGroup>
</Target>
I am using the latest .NET SDK.
—
Reply to this email directly, view it on GitHub
<#68108?email_source=notifications&email_token=BJVBQFKJYCVADNKEEUONDVT5H3ANHA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYGY3TMNRUUZZGKYLTN5XKOY3PNVWWK3TUUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#discussioncomment-17867664>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BJVBQFI6XOIITPL6WDHJ4RT5H3ANHAVCNFSNUABHKJSXA33TNF2G64TZHMYTONRSGAZTINZ3IRUXGY3VONZWS33OHMYTANJSGM3TAMFBOYBA>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/BJVBQFIFCWF6TJDT65IFTS35H3ANHA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYGY3TMNRUUZZGKYLTN5XKOY3PNVWWK3TUUVSXMZLOOSVGM33PORSXEX3JN5ZQ>
and Android
<https://github.com/notifications/mobile/android/BJVBQFJ72DPADUWS3AQDCQ35H3ANHA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYGY3TMNRUUZZGKYLTN5XKOY3PNVWWK3TUUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>.
Download it today!
You are receiving this because you commented.Message ID:
***@***.***>
|
|
Can you please accept my answer, it will help to improve my profile from
getting badges
…On Sun, 2 Aug 2026, 12:20 pm Vignesh Waran, ***@***.***> wrote:
<Project Sdk="Microsoft.NET.Sdk.Web">
<Target Name="NpmBuild"
BeforeTargets="AssignTargetPaths">
<Exec Command="npm install"
WorkingDirectory="Site"
Condition="'$(RunNPMCompilation)' == 'true'" />
<Exec Command="npm run build -- $(NPMArguments)"
WorkingDirectory="Site"
Condition="'$(RunNPMCompilation)' == 'true'" />
<ItemGroup>
<Content Include="wwwroot\assets\**\*"
CopyToOutputDirectory="PreserveNewest"
CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
</Target>
</Project>
If you're generating files directly into wwwroot
<Target Name="NpmBuild"
BeforeTargets="AssignTargetPaths">
<Exec Command="npm run build -- $(NPMArguments)"
WorkingDirectory="Site"
Condition="'$(RunNPMCompilation)' == 'true'" />
</Target>
On Sun, 2 Aug 2026 at 10:06, where where ***@***.***> wrote:
> This also not working. Dose before PreBuildEvent still too late?
>
> <Target Name="NPMBuild" BeforeTargets="PreBuildEvent">
> <Exec Command="npm run build -- $(NPMArguments)" WorkingDirectory="Site" Condition="$(RunNPMCompilation)" />
> <ItemGroup>
> <Content Include="wwwroot/assets/**/*" />
> </ItemGroup>
> </Target>
>
> I am using the latest .NET SDK.
>
> —
> Reply to this email directly, view it on GitHub
> <#68108?email_source=notifications&email_token=BJVBQFKJYCVADNKEEUONDVT5H3ANHA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYGY3TMNRUUZZGKYLTN5XKOY3PNVWWK3TUUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#discussioncomment-17867664>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/BJVBQFI6XOIITPL6WDHJ4RT5H3ANHAVCNFSNUABHKJSXA33TNF2G64TZHMYTONRSGAZTINZ3IRUXGY3VONZWS33OHMYTANJSGM3TAMFBOYBA>
> .
> Triage notifications, keep track of coding agent tasks and review pull
> requests on the go with GitHub Mobile for iOS
> <https://github.com/notifications/mobile/ios/BJVBQFIFCWF6TJDT65IFTS35H3ANHA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYGY3TMNRUUZZGKYLTN5XKOY3PNVWWK3TUUVSXMZLOOSVGM33PORSXEX3JN5ZQ>
> and Android
> <https://github.com/notifications/mobile/android/BJVBQFJ72DPADUWS3AQDCQ35H3ANHA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYGY3TMNRUUZZGKYLTN5XKOY3PNVWWK3TUUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>.
> Download it today!
> You are receiving this because you commented.Message ID:
> ***@***.***>
>
|
|
<Target Name="NPMBuild" BeforeTargets="AssignTargetPaths;PreBuildEvent">
<!-- Enable/disable npm build -->
<PropertyGroup>
<RunNPMCompilation Condition="'$(RunNPMCompilation)' ==
''">true</RunNPMCompilation>
<!-- Extra arguments when publishing -->
<NPMArguments Condition="'$(_IsPublishing)' == 'true'">
$(NPMArguments) --mode publish
</NPMArguments>
</PropertyGroup>
<!-- Remove old wwwroot content so MSBuild refreshes generated files -->
<ItemGroup>
<Content Remove="wwwroot\**\*" />
</ItemGroup>
<!-- Run npm build -->
<Exec
Command="npm run build -- $(NPMArguments)"
WorkingDirectory="Site"
Condition="'$(RunNPMCompilation)' == 'true'" />
<!-- Re-add newly generated files -->
<ItemGroup>
<Content Include="wwwroot\**\*" />
</ItemGroup>
</Target>
If you're using *.NET 8 or .NET 9*, this is generally the recommended
approach because it forces MSBuild to recognize the files that npm run build
generates in wwwroot before the build or publish process packages them.
… Message ID: <dotnet/aspnetcore/repo-discussions/68108/comments/17876831@
github.com>
|
|
<Target Name="GetFrameworkXmlDocumentation"
AfterTargets="ResolveReferences">
<ItemGroup>
<!-- Include XML documentation files for referenced assemblies -->
<Content Include="@(Reference->'%(RootDir)%(Directory)%(Filename).xml')"
Condition="Exists('%(RootDir)%(Directory)%(Filename).xml')" />
</ItemGroup>
</Target>
Explanation
- AfterTargets="ResolveReferences"
Runs after MSBuild has resolved all referenced assemblies.
- @(Reference->'%(RootDir)%(Directory)%(Filename).xml')
For every referenced DLL, this transforms its path to the corresponding
.xml documentation file.
- Condition="Exists(...)"
Only includes the XML file if it actually exists.
- <Content Include="..."/>
Adds the XML documentation file as project content so it can be copied
or published.
…On Mon, 3 Aug 2026 at 11:46, where where ***@***.***> wrote:
<Target Name="NPMBuild" BeforeTargets="PreBuildEvent">
<PropertyGroup>
<RunNPMCompilation Condition="$(RunNPMCompilation) == ''">false</RunNPMCompilation>
<NPMArguments>$(NPMArguments) --mode publish</NPMArguments>
</PropertyGroup>
<ItemGroup>
<Content Remove="wwwroot/assets/**/*" />
</ItemGroup>
<Exec Command="npm run build -- $(NPMArguments)" WorkingDirectory="Site" Condition="$(RunNPMCompilation)" />
<ItemGroup>
<Content Include="wwwroot/assets/**/*" />
</ItemGroup>
</Target>
This works now, VS has fixed it. Before it only works on publish build.
So how can I add other static assets like this...
<Target Name="GetFrameworkXmlDocumentation" AfterTargets="ResolveReferences">
<ItemGroup>
<Content Include="@(Reference->'%(RootDir)%(Directory)%(Filename).xml')" Condition="Exists('%(RootDir)%(Directory)%(Filename).xml')" />
</ItemGroup>
</Target>
—
Reply to this email directly, view it on GitHub
<#68108?email_source=notifications&email_token=BJVBQFJAARKXPIPFKD3MLXL5IAU4FA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYG43DSMZWUZZGKYLTN5XKOY3PNVWWK3TUUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#discussioncomment-17876936>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BJVBQFOIJKJOGW6XAXLFYD35IAU4FAVCNFSNUABHKJSXA33TNF2G64TZHMYTONRSGAZTINZ3IRUXGY3VONZWS33OHMYTANJSGM3TAMFBOYBA>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/BJVBQFLE4L6HQ7XUDDJMZYD5IAU4FA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYG43DSMZWUZZGKYLTN5XKOY3PNVWWK3TUUVSXMZLOOSVGM33PORSXEX3JN5ZQ>
and Android
<https://github.com/notifications/mobile/android/BJVBQFPLOYRR7JMCZ5RUY3T5IAU4FA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYG43DSMZWUZZGKYLTN5XKOY3PNVWWK3TUUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>.
Download it today!
You are receiving this because you commented.Message ID:
***@***.***>
|
|
ok
…On Mon, 3 Aug 2026 at 11:53, where where ***@***.***> wrote:
Could you please reply on GitHub? The reply layout is messy...
—
Reply to this email directly, view it on GitHub
<#68108?email_source=notifications&email_token=BJVBQFN3YOSI2DPV2ETUVW35IAVVPA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYG43DSOBXUZZGKYLTN5XKOY3PNVWWK3TUUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#discussioncomment-17876987>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BJVBQFM2TS6U7C4FHRFI3R35IAVVPAVCNFSNUABHKJSXA33TNF2G64TZHMYTONRSGAZTINZ3IRUXGY3VONZWS33OHMYTANJSGM3TAMFBOYBA>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/BJVBQFJZELFRVSFKE3USW6T5IAVVPA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYG43DSOBXUZZGKYLTN5XKOY3PNVWWK3TUUVSXMZLOOSVGM33PORSXEX3JN5ZQ>
and Android
<https://github.com/notifications/mobile/android/BJVBQFI3TWLAWQFZJFFJUVD5IAVVPA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYG43DSOBXUZZGKYLTN5XKOY3PNVWWK3TUUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>.
Download it today!
You are receiving this because you commented.Message ID:
***@***.***>
|
| Explanation AfterTargets="ResolveReferences" Runs after MSBuild has resolved all referenced assemblies. @(Reference->'%(RootDir)%(Directory)%(Filename).xml') For every referenced DLL, this transforms its path to the corresponding .xml documentation file. Condition="Exists(...)" Only includes the XML file if it actually exists. Adds the XML documentation file as project content so it can be copied or published. |
|
i dont know but how i send it's all messed up . The format was irregular i dont know why sorry |
<Target Name="GetFrameworkXmlDocumentation"
AfterTargets="ResolveReferences">
<ItemGroup>
<!-- Include XML documentation files for referenced assemblies -->
<Content Include="@(Reference->'%(RootDir)%(Directory)%(Filename).xml')"
Condition="Exists('%(RootDir)%(Directory)%(Filename).xml')" />
</ItemGroup>
</Target> |
|
sorry that was my mistake here your codee |
|
I tried using the following target so that the XML documentation files are included during both build and publish: <Target Name="GetFrameworkXmlDocumentation"
BeforeTargets="AssignTargetPaths;Publish">
<ItemGroup>
<Content Include="@(Reference->'%(RootDir)%(Directory)%(Filename).xml')"
Condition="Exists('%(RootDir)%(Directory)%(Filename).xml')">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
</Target>Would this be the recommended approach for including additional generated static assets, or is there a better SDK-supported mechanism? |
|
please verify the answer |
|
Ok sir
…On Mon, 3 Aug 2026, 12:27 pm where where, ***@***.***> wrote:
It needs to wait for a contributor...
—
Reply to this email directly, view it on GitHub
<#68108?email_source=notifications&email_token=BJVBQFONJ35B3ETFN4VUL2D5IAZU3A5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYG43TGMBUUZZGKYLTN5XKOY3PNVWWK3TUUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#discussioncomment-17877304>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BJVBQFPC2RIQBXQRSFY43VL5IAZU3AVCNFSNUABHKJSXA33TNF2G64TZHMYTONRSGAZTINZ3IRUXGY3VONZWS33OHMYTANJSGM3TAMFBOYBA>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/BJVBQFIJ6FZDLKPHAV32X4D5IAZU3A5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYG43TGMBUUZZGKYLTN5XKOY3PNVWWK3TUUVSXMZLOOSVGM33PORSXEX3JN5ZQ>
and Android
<https://github.com/notifications/mobile/android/BJVBQFKG2VRZCI6T5JGBSVD5IAZU3A5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYG43TGMBUUZZGKYLTN5XKOY3PNVWWK3TUUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>.
Download it today!
You are receiving this because you commented.Message ID:
***@***.***>
|

I tried using the following target so that the XML documentation files are included during both build and publish:
Would this be the recommended approach for including additional generated static assets, or is there a better SDK-supported mechanism?