Error reported by mvcscaffolding in MVC4 project

Aug 17, 2012 at 10:29 PM

Upon opening a console window in VS12 (rtm)  - MVC4 project

Exception calling "EnumerateFiles" with "3" argument(s): "The path is not of a legal form."
At C:\Users\foo\package
s\MvcScaffolding.1.0.7\tools\init.ps1:23 char:45
+         | %{ [System.IO.Directory]::EnumerateFiles <<<< ($_, "*." + $extensio
n, [System.IO.SearchOption]::AllDirectories) }
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

 

something specific to my installation or compatibility at the package level?

Dec 18, 2012 at 2:33 PM

I'm getting the same thing in version 1.0.8 .

 

Exception calling "EnumerateFiles" with "3" argument(s): "The path is not of a legal form."At C:\Users\rwilkerson\Code\Spot Projects\Dev\Sprint 12\Sprint\src\packages\MvcScaffolding.1.0.8\tools\init.ps1:35 char:45+         | %{ [System.IO.Directory]::EnumerateFiles <<<< ($_, "*." + $extension, [System.IO.SearchOption]::AllDirectories) }    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException    + FullyQualifiedErrorId : DotNetMethodException 

Sep 1, 2013 at 8:25 PM
After debugging this for a while I found that some Project Types return a Blank path. You can filter these out by adding a filter before the EnumerateFiles call so that the blanks are taken out.
         | ?{$_}`
The function should then look like this:
function CountSolutionFilesByExtension($extension) {
    $files = (Get-Project).DTE.Solution`
         | ?{ $_.FileName }`
         | %{ [System.IO.Path]::GetDirectoryName($_.FileName) }`
         | ?{$_}`
         | %{ [System.IO.Directory]::EnumerateFiles($_, "*." + $extension, [System.IO.SearchOption]::AllDirectories) }
    ($files | Measure-Object).Count
}
This works for any project types, including Wix Projects that seem to give issues for the Get-Project call.
This solution was still needed for the init.ps1 file in version 1.0.9.
Hope this helps someone.