简体   繁体   English

如何从.csproj文件中知道计算机上是否安装了nodejs?

[英]How can I know from a .csproj file if nodejs is installed on the computer?

I am building *.less files using a custom target in *.csproj and the original compiler that requires nodejs. 我正在使用* .csproj中的自定义目标和需要nodejs的原始编译器来构建* .less文件。 Node isn't available on all development machines, so I need to be able to switch off the target if node isn't present on a computer. 节点并非在所有开发机器上都可用,因此如果计算机上不存在节点,则需要能够关闭目标。 How can I do that? 我怎样才能做到这一点?

<Target Name="CompileLessCss" BeforeTargets="Compile"
        Inputs="@(LessCssRoot);@(LessCssInput)" Outputs="@(LessCssOutput)">
    <Exec Command="node &quot;$(SolutionDir)/Tools/less.js/bin/lessc&quot; --verbose @(LessCssRoot) @(LessCssOutput)" ConsoleToMSBuild="true">
      <Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
    </Exec>
</Target>

You can either check if a nodejs path is available in the $(PATH) variable. 您可以在$ {PATH)变量中检查nodejs路径是否可用。 Or you can execute node once with continue on error to determine if it is installed with the exec task, not pretty but it works. 或者,您可以执行一次节点并继续执行错误,以确定该节点是否与exec任务一起安装,虽然不是很漂亮,但是可以工作。

<Exec ContinueOnError="True"  Command="node --help">
  <Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
</Exec>

<PropertyGroup>  
  <NodeInstalled>False</NodeInstalled>      
  <NodeInstalled Condition=" '$(ErrorCode)' == '0' ">True</NodeInstalled>
</PropertyGroup>

<Exec Command="node [args]"  Condition=" '$(NodeInstalled)' == 'True' " /> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当 MeteorJS 已经安装在同一台计算机上时,我可以安装 NodeJS 吗? 它会损坏流星吗? - Can I install NodeJS when MeteorJS already installed on the same computer? Does it damage Meteor? 如何使用服务器域名从本地计算机访问我的nodejs Web服务器? - How can I access my nodejs web server from my local computer using the server domain name? 我如何知道 angular 7.1.4 是否已正确安装? - How can i know angular 7.1.4 is properly installed? 如何从 nodejs 中的 typescript 文件中读取 object? - How can I read an object from a typescript file in nodejs? 如何从服务器在客户端上执行 exe 文件? 节点 - How can I execute a exe file on client from the server? Nodejs 如何从我的 nodejs 服务器中删除文件 - How can i delete a file from my nodejs server NodeJS,如何从批处理文件中使用“永远启动”? - NodeJS, how can I use 'forever start' from a batch file? NodeJS是如何从ubuntu运行两个服务器文件? - NodeJS is how can I run two server file from ubuntu? 如何将带有nodejs的文件下载到本地计算机? - How to download a file with nodejs to local computer? 如果我在 docker swarm 上部署我的 nodejs 应用程序,我可以从其他计算机访问 rest-api 吗? - can i access the rest-api from other computer if i deploy my nodejs application on docker swarm?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM