I discussed moving Visual Studio solutions to TFS + Git powered cloud-based source control in my previous blog post. As I was migrating my remaining projects over, I stumbled upon a bug that gratefully did not take too long to figure out. I will share the problem and the solution with you, my fellow reader.
While creating a Git repository on your TFS account, it is possible to provide a project name that has a white space in it. This is perfectly valid. Below, I’ve created a project with the name “Half Baked”
I added my solution to source control, committed the initial change which adds all the files and finally pushed the commit to the new Git repository. I like to make sure that it really did work, so the next step is to verify that by cloning the repository to a different local path.
When you want to clone a project that has white space in it, the Visual Studio Tools for Git add-on URL escapes the project name. The filename it offers has spaces replaced with ‘%20’. This is a valid filename on Windows. Since I was just trying to verify the source integrity, I didn’t care too much about the path, so I set the folder to a different one (“TFS-verify”) and I kept the escaped characters.
When I tried to rebuild the solution however, it failed miserably.
In the Error List window, the error messages were in the form:
Source file ‘C:\TFS-Verify\Half Baked\…\filename.cs’ could not be found
In the Output window, the error messages were in the form:
CSC : error CS2001: Source file ‘C:\TFS-Verify\Half Baked\…\filename.cs’ could not be found
A quick web search for CS2001 brought up a few links where people were hitting the issue in an ASP.NET context and the culprit was that C:\Windows\Temp was not writable. This was irrelevant in my case. Indeed, the path and the file were not only accessible, but they were being created during build. Somehow they couldn’t be accessed by the C# compiler (CSC.exe).
The real reason was the presence of %20 in the path. This appears to be a CSC bug, where the tool is not looking in the correct location. In fact, if you copy the error message from the Error List window and paste it into notepad, it provides more information than what’s readily visible in the window:
Source file ‘C:\TFS-Verify\Half Baked\…\filename.cs’ could not be found C:\TFS-Verify\Half%20Baked\…\filename.cs projectname
Notice the discrepancy between the first path and the second path.
I solved the problem by getting rid of the clone with the problematic path and created another in a path that has a space instead of the %20. Everything worked well after that.