Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The desired name for <file> is invalid - visual studio 2015

This is pretty crazy, I am only adding an existing .h file to VS2015 C++ project but it would complain:

The desired name for c:\code\usbview\USBdevices.h is invalid

I was able to add this file to project when it had its own .sln file. However, I created a new empty .sln file and wanted to add this and other project and that's how this issue kicked in. It wouldn't add this project to new solution giving a similar weird error about the files I added.

I then add the base project to that solution file and tried to add this .h and .cpp files there but it adds the .cpp but gives this error for .h file.

This is very weird, I changed the files names but the same error.

like image 696
zar Avatar asked Nov 25 '15 16:11

zar


4 Answers

The link in the comment section by BlackDwarf fixed the problem even though that was was for C# but applies.

I didn't have USERPROFILE environment variable so I created it and set it to c:\Users\my.name and now I can add the file

like image 99
zar Avatar answered Nov 03 '22 23:11

zar


I had the same problem and it was because of merge errors in the file ProjectName.vcxproj.filters.

like image 39
habakuk Avatar answered Nov 04 '22 00:11

habakuk


The answers here led me to check my vcxproj when I experienced the OP's problem. It turns out I had two filters with the same name in my Project.vcxproj.filters, something like

<Project>
  <Common>
  ...
  ...
  <Stuff>
     <Common>

And I was trying to add files to the second Common.

To fix it, I had to ..

  • edit the vcxproj manually in {favoured text editor} and remove the second filter I'd added with a duplicate name.
  • Unload/Reload the project from the solution in VS(2017), and add a filter with a unique name. All good - I can add files to my new filter.
like image 1
coolhandle01 Avatar answered Nov 03 '22 23:11

coolhandle01


I use VS 2013 Express and had the same error.

Solved by removing VCTargetsPath environment variable, I added it some time ago, don't remember why :)

like image 1
Dmytro Avatar answered Nov 04 '22 00:11

Dmytro