1

I get the error below when I try to create a new project. I've upgraded to CTP2. Error:

The expression """.Substring(0, 6)" cannot be evaluated. Index and length must refer to a location within the string. Paramter name: length C:\USERS\ME\AppData\Roaming\npm\node_modules\vs-mda-targets\Microsoft.MDA.targets

When this error occurs and I check the solution folder, no project has been created.

Priyank
  • 1,568
  • 10
  • 15
ritcoder
  • 3,274
  • 10
  • 42
  • 62

2 Answers2

10

With VS closed, in a command window, run
npm -g uninstall vs-mda and npm -g uninstall vs-mda-targets

Check to see if this removed the vs-mda and vs-mda-targets folders under
C:\Users\YOUR-USER-NAME\AppData\Roaming\npm\node_modules\
If it didn't, you can delete those folders manually.

Then relaunch VS and create an MDHA project. It should work successfully.

If you get an error on project creation saying that the MDA targets were not found, you can manually install 'vs-mda' & 'vs-mda-targets' from under Visual Studio's Extension folder to get things working again.

Exit Visual Studio and on the drive where Visual Studio is installed, navigate to
%Program Files%\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\uxbwjkun.gjn*\packages
Here you will find two folders "vs-mda" and "vs-mda-targets"

  • Note that uxbwjkun.gjn will not be the exact folder name, but look for something like it that contains packages folder.

Now from here run npm -g install <full path to current folder>\vs-mda and npm -g install <full path to current folder>\vs-mda-targets

When issuing this command it's necessary to give it the explicit path to the vs-mda and vs-mda-targets folders under the VS installation in %Program Files%.

Relaunch and create a new MDHA project.

Ellen
  • 1,189
  • 7
  • 9
  • I had an error which looks like ``The imported project "...\node_modules\vs-mda-target\microsoft.mda.targets" was not found``. The output after executing the above command was ``unbuild vs-mda-targets@0.1.0``. I could not reinstall though with ``npm install -g vs-mda-targets`` – ritcoder Aug 27 '14 at 02:06
  • I have updated my answer to describe how to handle the missing targets files. – Ellen Aug 27 '14 at 08:04
  • I do not have an extensions folder in ``C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE``. I have ``CommonExtensions``, ``PrivateAssemblies``, and `Remote Debugger``. I'll try searching for the other folders – ritcoder Aug 29 '14 at 15:33
  • I found a copy in ``npm-cache``. After copying it to the folder specified, I'm getting the original error. – ritcoder Aug 29 '14 at 23:33
  • Unfortunately, the copy from the npm-cache is the original stale copy, which is why you are getting the original error. It sounds like you have VS installed to a non-system drive. In that case, you will find the Extensions folder under the Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE on the drive where VS is installed. Please repeat the steps in the answer above, including uninstalling the targets files and on the installed drive, finding the folder underneath Extensions that has the packages folder and copying from there. – Ellen Sep 02 '14 at 20:12
  • It worked. I am able to generate the project now after copying the files you specified. I'm getting the following error though when I try building: ``Cannot find module 'q'`` and ``The command ""\AppData\Roaming\npm\node_modules\vs-mda\vs-cli" prepare --platform Android --configuration Debug --projectDir . --projectName "BlankCordovaApp5" --language "en-US"" exited with code 8. \AppData\Roaming\npm\node_modules\vs-mda-targets\Microsoft.MDA.targets 182`` – ritcoder Sep 03 '14 at 02:07
  • Evidently just copying vs-mda and vs-mda-targets folders is not sufficient to install a node module. I have updated the above answer with a better way to fully install these packages from their source under %Program Files%. Let me know if that unblocks you. – Ellen Sep 06 '14 at 01:30
  • I'm getting a 404 for the two packages. ``npm http 404 https://registry.npmjs.org/vs-mda-targets`` and ``npm http 404 https://registry.npmjs.org/vs-mda`` – ritcoder Sep 07 '14 at 12:45
  • Rather than navigating to the packages folder under your VS installation, try issuing the npm install commands using the paths to the vs-mda and vs-mda-targets folders directly. As in npm -g d:\\vs-mda and npm -g d:\\vs-mda-targets – Ellen Sep 08 '14 at 14:53
  • I tried ``npm -g C:\Users\user\appdata\roaming\npm\node_modules\vs-mda``. The result was some text telling me how to use ``npm``. Is the command right? – ritcoder Sep 09 '14 at 02:59
  • You need to use the full paths of the vs-mda and vs-mda-targets folders under your VS installation folder which will be in your Program Files (where you found the packages folder earlier when you did the copy). That is the source you want to use for this install. The folders under your users path is the destination where the command will end up installing them to. – Ellen Sep 09 '14 at 17:02
  • Tried it and it worked now. I can create the project and compile successfully. I'm unable to deploy directly to the device or emulator but at the least seeing the apk for the android app so that is one problem solved. Thanks. – ritcoder Sep 15 '14 at 19:22
  • Thanks, Ellen. This one was driving me bonkers. – jeffa00 Mar 02 '15 at 02:33
  • I search all folders in my drive's that vs installed. but I can not found this folder. I use vs 2015. please help me – mina morsali Mar 16 '16 at 16:15
5

Quite a few of our devs had to solve this one on our team, so I created a script to fix this for them after the upgrade to CTP3. It basically does what Ellen's solution does, but it does it automatically by looking up the Registry entry for the VS Extension path :)

Create a .cmd file with the following contents:

@echo off
setlocal ENABLEEXTENSIONS
echo -- Searching for MultiDeviceHybridApp Visual Studio Extension --
set KEY_NAME=HKEY_USERS\.DEFAULT\Software\Microsoft\VisualStudio\12.0\ExtensionManager\EnabledExtensions
set SEARCH_VALUE=MultiDeviceHybridApp
set REG_QUERY_CMD=reg query "%KEY_NAME%" /f "%SEARCH_VALUE%"
for /f "tokens=2*" %%a in ('%REG_QUERY_CMD% 2^>^&1^|find "REG_"') do @set RESULT_REG_VALUE=%%b
goto find_result_%ERRORLEVEL%
:find_result_0
echo Found here: %RESULT_REG_VALUE%
set PACKAGES_PATH=%RESULT_REG_VALUE%\packages
echo Installing vs mda packages....
echo.
set CMD=npm -g uninstall "%PACKAGES_PATH%\vs-mda-targets"
echo Running: %CMD%
call %CMD%
echo.
set CMD=npm -g uninstall "%PACKAGES_PATH%\vs-mda"
echo Running: %CMD%
call %CMD%
echo.
set CMD=npm -g install "%PACKAGES_PATH%\vs-mda"
echo Running: %CMD%
call %CMD%
echo.
set CMD=npm -g install "%PACKAGES_PATH%\vs-mda-targets"
echo Running: %CMD%
call %CMD%
echo.
echo Done!
goto end
:find_result_1
echo *** Could not find MultiDeviceHybridApp Visual Studio Extension path ***
:end
pause

Run this file and it should uninstall and reinstall the npm packages correctly for you!

PS. You will obviously need npm to be part of your system path.

Mark Whitfeld
  • 6,500
  • 4
  • 36
  • 32