One of my team members encountered an unexpected error during compilation recently:
```
RazorGenerator.targets(31,9): error MSB4018: The "RazorCodeGen" task failed unexpectedly.
RazorGenerator.targets(31,9): error MSB4018: System.ArgumentException: Illegal characters in path.
```
It turned out to be a bogus error message triggered by the addition of a node.js-module. The package manager _npm_ stores all project local packages in a subdirectory called _node_modules_, and this directory structure can get pretty deep as each module can have its own _node_modules_-directory. Once the path is longer than 260 characters (Windows API’s MAX_PATH), MSBuild breaks down and prints this bogus error.
The reason this occurs with Razor Generator is because of the following wildcard inclusion:
```
<ItemGroup>
<RazorSrcFiles Condition=" '@(RazorSrcFiles)' == '' " Include="**\*.cshtml" />
…
</ItemGroup>
```
It doesn’t seem to help excluding node_modules either; at least I wasn’t successful. Perhaps MSBuild traverses the directory structure before it excludes an item.
One possible solution is to move the item group inside the target PrecompileRazorFiles, and then build it by filtering the Content item group (created by Visual Studio):
```
<Target Name="PrecompileRazorFiles"
Inputs="@(RazorSrcFiles)"
Outputs="@(RazorOutputFiles)">
<ItemGroup>
<RazorSrcFiles Include="@(Content)" Condition=" '@(RazorSrcFiles)' == '' And %(Extension) == '.cshtml' " />
<RazorOutputFiles Include="@(RazorSrcFiles -> '$(RazorViewsCodeGenDirectory)%(RelativeDir)%(Filename)%(Extension).cs')" />
</ItemGroup>
<RazorCodeGen ProjectRoot="$(MsBuildProjectDirectory)"
…
</Target>
```
What do you think? Would it be possible to include this change in an official release, or do you know of a better solution?
I know I can fix this myself by scanning a known subset of directories before including this target, or by using a variant of the above method: my own target with a "BeforeTargets" construct combined with a dummy RazorSrcFiles-item to prevent the default scan from occurring (for want of a better conditional property). But I figure others will run into the same problem eventually, so maybe you want to fix it as well.
```
RazorGenerator.targets(31,9): error MSB4018: The "RazorCodeGen" task failed unexpectedly.
RazorGenerator.targets(31,9): error MSB4018: System.ArgumentException: Illegal characters in path.
```
It turned out to be a bogus error message triggered by the addition of a node.js-module. The package manager _npm_ stores all project local packages in a subdirectory called _node_modules_, and this directory structure can get pretty deep as each module can have its own _node_modules_-directory. Once the path is longer than 260 characters (Windows API’s MAX_PATH), MSBuild breaks down and prints this bogus error.
The reason this occurs with Razor Generator is because of the following wildcard inclusion:
```
<ItemGroup>
<RazorSrcFiles Condition=" '@(RazorSrcFiles)' == '' " Include="**\*.cshtml" />
…
</ItemGroup>
```
It doesn’t seem to help excluding node_modules either; at least I wasn’t successful. Perhaps MSBuild traverses the directory structure before it excludes an item.
One possible solution is to move the item group inside the target PrecompileRazorFiles, and then build it by filtering the Content item group (created by Visual Studio):
```
<Target Name="PrecompileRazorFiles"
Inputs="@(RazorSrcFiles)"
Outputs="@(RazorOutputFiles)">
<ItemGroup>
<RazorSrcFiles Include="@(Content)" Condition=" '@(RazorSrcFiles)' == '' And %(Extension) == '.cshtml' " />
<RazorOutputFiles Include="@(RazorSrcFiles -> '$(RazorViewsCodeGenDirectory)%(RelativeDir)%(Filename)%(Extension).cs')" />
</ItemGroup>
<RazorCodeGen ProjectRoot="$(MsBuildProjectDirectory)"
…
</Target>
```
What do you think? Would it be possible to include this change in an official release, or do you know of a better solution?
I know I can fix this myself by scanning a known subset of directories before including this target, or by using a variant of the above method: my own target with a "BeforeTargets" construct combined with a dummy RazorSrcFiles-item to prevent the default scan from occurring (for want of a better conditional property). But I figure others will run into the same problem eventually, so maybe you want to fix it as well.