MSBuild can't exec command `npm i` while compiling a project in Rider/Visual Studio - msbuild

I need to build and run a .NET 5 project in Mac using Visual Studio for Mac or Jetbrains Rider.
In csproj file of one of the projects in the solution, I have following Target:
<Target Name="SassBuild" BeforeTargets="Build" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Exec Command="npm i" />
<Exec Command="npm rebuild node-sass" />
<Exec Command="npm run gulp-sass" />
<Exec Command="npm run gulp-js" />
</Target>
When I run dotnet build or dotnet msbuild project builds just fine, however building it in VS/Rider throws the following error:
Error MSB3073: The command "npm i" exited with code 127. (MSB3073)
Details in the log:
Target SassBuild:
npm i
/var/folders/9l/d02_tk1j5f93vklft82p1z996dm09b/T/tmp89785a0aeebb4347a3696de11d8c281e.exec.cmd: line 2: npm: command not found
PATH_TO_CSPROJ_HERE.csproj(232,5): error MSB3073: The command "npm i" exited with code 127.
Done building target "SassBuild" in project "X.csproj" -- FAILED.
npm is installed already and I can run the npm commands in terminal. I use nvm for node versioning.
Any ideas?

Alright, I figured out that Mac OS terminal and VS/Rider terminals are not fed from the same terminal configuration files; that's why the IDEs weren't able to find the npm in their paths.
I copied all the nvm related configuration from ~/.zprofile to ~/.profile and now I am able to build the project in VS/Rider.
Hope it helps anyone having the same problem.

Related

aspnet-codegenerator: No code generators available, Even after adding Microsoft.VisualStudio.Web.CodeGeneration.Design

Unable to generate scaffolding using aspnet-codegenerator, below is what I tried:
Created an ASP.Net RazorPages application using
dotnet new webapp
Did a dotnet build
Installed dotnet-aspnet-codegenerator using
dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.4
Ran dotnet aspnet-codegenerator --help
It says: No code generators are available in this project.Add Microsoft.VisualStudio.Web.CodeGeneration.Design package to the project as a NuGet package reference.
Added the package mentioned in step 4 using
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
Package added is:
<ItemGroup> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" /> </ItemGroup>
Again ran: dotnet build
Final-Step
Ran dotnet aspnet-codegenerator --help
Again it says: No code generators are available in this project.Add Microsoft.VisualStudio.Web.CodeGeneration.Design package to the project as a NuGet package reference.
.Net core installed version: 3.1.401
Os: Ubuntu 20.04
This is already a few month old, but I ran into it recently for all my projects.
In case someone else lands on this page, the solution in my case(MAC OS), was to uninstall and reinstall dotnet-aspnet-codegenerator.
Run in terminal:
dotnet tool uninstall --global dotnet-aspnet-codegenerator
dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.4
I have same problem when upgrade from .net core 3.1.4 to 5.0.1.
My solution:
update global tools:
dotnet tool install --global dotnet-aspnet-codegenerator
dotnet tool update --global dotnet-aspnet-codegenerator
dotnet tool install --global dotnet-ef
dotnet tool update --global dotnet-ef
add/update links to packages
dotnet remove package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet add package Microsoft.EntityFrameworkCore.Design
Replace string netcoreapp3.1.4 to net5.0 in .csproj and launch.json files
Clear directories
bin
obj
Rebuild project
Finally run:
dotnet aspnet-codegenerator --help
If all fine it will show available generators.
The root cause of this problem has been described in this issue as the .NET code expecting a case-insensitive filesystem which fails on a Linux host.
A suggested workaround would be to temporarily mount you ~/.nuget directory on a vfat filesystem.
To do so create a dummy file holding the filesystem
dd if=/dev/zero of=/tmp/mynuget bs=1024k count=2000
mkfs.vfat /tmp/mynuget
and then mount it
sudo mount -o uid=myuser,gid=myuser -t vfat /tmp/mynuget /home/myuser/.nuget
and use it
dotnet restore
dotnet aspnet-codegenerator ...
I test your command,and when I do this dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.4,I can get
and then Ran dotnet aspnet-codegenerator --help,I get the same message No code generators are available in this project.Add Microsoft.VisualStudio.Web.CodeGeneration.Design package to the project as a NuGet with you,
but when I do the following,I can run without the message:
I think maybe the package is not added correctly,you can try to remove and add it again.
dotnet remove package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
I have found the SOLUTION to this issue:
The newest versions are giving some problems, so you will have to downgrade the version of the sdk to the 3.1.3 by writing this command on the terminal:
sudo apt install dotnet-sdk-3.1=3.1.301-1
After that you will need to install the following:
dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.3
After that you will need to add the right Web.CodeGeneration.Design Package by writing this on the terminal:
sudo apt install dotnet-sdk-3.1=3.1.301-1
dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.3
That has worked for me!!

Change Task Runner Explorer command

In Visual Studio 2019 I have installed the extension call NPM Task Runner.
When I run a the build command the output is:
cmd.exe /c npm run build --color=always
How do I change that to:
npm run build --color=always
Because when I run the first one I get an error.
How can I fix the error or change the command.
P.S.: When I run the command like this npm run build --color=always in the console it works.
This fixed the problem for me.
Tools > Options > Projects and Solutions > Web Package Management >
External Web Tools
Move the $(PATH) entry to the 2nd position in the list by using the
up arrow button.
Post: Executes wrong version of nodejs

Debug CMake Project Creation

I am facing a specific problem, and want advice or a way to debug it.
I am building the Allegro library from source, using: Windows 10, CMake, and Visual Studio 2015 build tools (msbuild).
Source: https://github.com/liballeg/allegro5
The problem is that when I run `cmake --build .' I am getting errors stating that the v100 toolset isn't installed, however I'm making it for Visual Studio 2015, and not 2010. If I open up the solution, or run msbuild directly, it builds perfectly fine.
Is there a way to Debug CMake that will help me see the issue?
Failing Commands:
mkdir _build
pushd _build
cmake.exe ..
cmake --build .
popd
Error:
"C:\Users\matthew\repos\allegro5_build\ALL_BUILD.vcxproj" (default
target) (1) ->
"C:\Users\matthew\repos\allegro5_build\ZERO_CHECK.vcxproj" (default
target) (2) -> (PlatformPrepareForBuild target) -> C:\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets(55,5):
error MSB8020: The build tools for Visual Studio 2010 (Platform
Toolset = 'v100') cannot be found. To build using the v100 build
tools, please install Visual Studio 2010 build tools. Alternatively,
you may upgrade to the current Visual Studio tools by selecting the
Project menu or right-click the solution, and then selecting "Retarget
solution". [C:\Users\matthew\repos\allegro5
_build\ZERO_CHECK.vcxproj]
Working Commands:
mkdir _build
pushd _build
cmake.exe ..
msbuild ALLEGRO.sln
popd
I've also tried forcing it to Visual Studio 2015 with commands like:
cmake.exe -G "Visual Studio 14" ..
Note: I've built my own small project with CMake and it builds correctly using CMake --build
To me it seems like something crazy with the allegro cmake build. I have searched through the source to try and find references to v100 and MSVC_2010, but found nothing of concern.
I don't want to directly use MSBuild as a work-around because I want to include allegro with ExternalProject_Add, and that fails for the same reason as building it with cmake --build.
How can I go about solving this issue?
I had a similar problem with another library (Zipper, a C++ wrapper around minizip). I was also using CMake and ExternalProject_Add in particular. Exact same error. I spent a lot of time researching the issue. I found a similar problem with another project using Gyp (have a look at the "Known issue" section). For me, the error was occurring during the install target. Changing
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config Release
to
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config Release --target install
INSTALL_COMMAND ""
fixed the issue. Not sure what the problem is. It seems like the default install command CMake uses in an ExternalProject picks the wrong toolset somehow...

.net WebDeploy is there any way to run command/script on the target machine after deploy

I have and .net/angular2 application, I'm publishing with WebDeploy.
But when the publish finish I wanna run some command on the target machine like
npm install
npm run tsc
There is a way to do that?
You should be able to use the postSync argument:
msdeploy -verb:sync -source:contentPath="C:\Test1" -dest:contentPath="C:\Test2" -postSync:runcommand="c:\MyBatchFile.bat"
https://technet.microsoft.com/en-us/library/dd569089(v=ws.10).aspx

How can I run grunt on AppHarbor through MSBuild?

I can build my solution with MSBuild. It runs grunt and generates a "dist" folder within the solution directory, and MSBuild then copy those files to $(OutDir).
Let's say my solution is called  MySolution.sln. I have next to it another file called after.MySolution.sln.targets which contains
<!--?xml version="1.0" encoding="utf-8"?-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Grunt" AfterTargets="Build">
<Exec Command="grunt build --no-color" WorkingDirectory="$(MSBuildProjectDirectory)" />
<ItemGroup>
<DistFiles Include="$(MSBuildProjectDirectory)\dist\**\*.*" />
</ItemGroup>
<Copy SourceFiles="#(DistFiles)" DestinationFolder="$(OutDir)\www\%(RecursiveDir)" />
</Target>
</Project>
When AppHarbor builds the solution, I receive this error
Grunt:
grunt build --no-color
'grunt' is not recognized as an internal or external command,
operable program or batch file.
Which is understandable, if grunt-cli was not already made available by AppHarbor. How then can I run my grunt build on AppHarbor?
Note: Technically, to run grunt successfully, I need to run npm install and bower install, so kudos if the answer also covers grunt packages and bower packages!
In order to run my build, I had to use node directly rather than grunt-cli. My MSBuild now simply calls run-grunt.bat, which contains:
#echo off
echo Installing npm dependencies
call npm config set registry http://registry.npmjs.org/
call npm install
echo Running bower.commands.install()
call node -e "var b = require('bower'); b.commands.install()"
echo Running grunt.cli()
call node -e "var g = require('grunt'); g.cli.tasks = ['build']; g.cli.options.color = false; g.cli();"
It seems to work; the next issue is that node on the build servers is still at version 0.6.10, but that's another problem :)
Note that I add the registry because otherwise it didn't work (I'll have to check with AppHarbor), and since I use bower and probably other people will too, I included in my example how to run bower install.
Important: you'll need to include grunt (and bower if you use it) in your packages.json file!