Thursday, January 9, 2020

Publishing node_modules in .Net Core

How to automate the npm install, when you publish your .net core project,
and make sure the publish operation include the node_modules folder created

please follow the next steps to do this solution


  1. double click on the project or right click on the project and select edit, you will open .csproj file, you will find xml data
  2. exclude the node_modules from your project
  3. remove the ItemGroup which contains the reference the node_modules files
  4. write the following code
    <Target Name="PostBuild" AfterTargets="ComputeFilesToPublish">
    <Exec Command="npm install" />
    </Target>
         <ItemGroup>
    <Content Include="node_modules/**" CopyToPublishDirectory="PreserveNewest" />
    </ItemGroup>
  5. finally run the publish command "dotnet publish -o c:\temp\publish"






No comments:

Post a Comment