简体   繁体   中英

Package NodeJS Dependencies with C# Nuget Package

Is there a way to bundle NodeJS/Npm dependencies in a Nuget Package without including the entire node_modules folder? I am looking for maybe a post-install hook, where when a user installs the package, a command is automatically triggered to run npm install in the respective folder. Does something like this exist in Nuget/C#? Or am I better off compiling it all into a single file and using that in my project instead (via NodeServices)?

I dont think you can do that but there is a way for you to run npm install when you build your solution by edit your csproj file like this

  <Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
    <!-- Ensure Node.js is installed -->
    <Exec Command="node --version" ContinueOnError="true">
      <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
    </Exec>
    <Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
    <Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
  </Target>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM