1

Intro

I'm working on a visual studio solution that has multiple projects, one of them is an mvc server, and another is a node project for building the js/css and managing the fonts and images.

I want to make it so that, whenever I build/run the mvc project the node project gets built too.

What I tried

I tried to solve this by adding the node project as a reference to the c# project (Right click on dependencies, add project reference, check node project, ok). But I got this error:

NU1105 Unable to find project information for 'path_to_node_project.njsproj'. If you are using Visual Studio, this may be because the project is unloaded or not part of the current solution so run a restore from the command-line. Otherwise, the project file may be invalid or missing targets required for restore.

I checked the answers for this question but none of them worked.

Question

How can I fix the NU1105 error, and if that's not possible, or the correct approach, how can I tell visual studio to build the node project whenever the mvc project gets built?

Additional File Info

.njsproj file (generated by visual studio):

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
    <Name>ProjectName</Name>
    <RootNamespace>ProjectName</RootNamespace>
    <EnableTypeScript>true</EnableTypeScript>
    <TypeScriptSourceMap>true</TypeScriptSourceMap>
    <TypeScriptModuleKind>CommonJS</TypeScriptModuleKind>
  </PropertyGroup>
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>6b2a4d69-3d59-48a3-abd3-ba5e3744f494</ProjectGuid>
    <ProjectHome>.</ProjectHome>
    <StartupFile>
    </StartupFile>
    <StartWebBrowser>False</StartWebBrowser>
    <SearchPath>
    </SearchPath>
    <WorkingDirectory>.</WorkingDirectory>
    <OutputPath>.</OutputPath>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <ProjectTypeGuids>{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}</ProjectTypeGuids>
    <StartWebBrowser>false</StartWebBrowser>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>
  <ItemGroup>
  ...
  </ItemGroup>
  <Import Project="$(VSToolsPath)\Node.js Tools\Microsoft.NodejsToolsV2.targets" />
</Project>

package.json The build and clean commands of the node project work as expected (both from the console and by right clicking on the node project from visual studio).

{
    "name": "projectname",
    "version": "1.0.0",
    "description": "Front end build for site",
    "main": "build.js",
    "scripts": {
        "build": "node build.js",
        "clean": "node clean.js"
    },
    "keywords": [],
    "author": "",
    "license": "ISC"
}

nick zoum
  • 7,216
  • 7
  • 36
  • 80
  • Do you use visual studio extension? Like [this one](https://visualstudio.microsoft.com/vs/features/node-js/)? Otherwise you simply need post-build event. – Sinatr Jun 23 '21 at 14:49
  • @Sinatr No I don't have any additional node extensions on vs. But if I just right-click on the node project and click rebuild it works fine. I just want to link it to the cs project so that all the front end files get automatically updated. – nick zoum Jun 23 '21 at 14:57
  • @Sinatr I've added a `cd` and `npm run build` command in the post build event, so now the other project gets built as well. However I would still like to know what I've done wrong. – nick zoum Jun 23 '21 at 16:57

0 Answers0