[英]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 "$(SolutionDir)/Tools/less.js/bin/lessc" --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.