MSBuild error "CSC : error CS2001: Source File 'x' could not be found" with Linked Files after upgrading to Visual Studio 2012 - visual-studio-2012

After automatically upgrading the project file for a .Net 4.0 web application to work with Visual Studio 2012 everything worked ok at first however when compiling I got lots of errors like this:
Description : Source File '..\..\..\..\..\File Path' could not be found
File : CSC
And when trying to build using MSBuild (passing just the project full path, with no additional parameters) in the "Developer Command Prompt for VS2012" I got basically the same errors:
"CSC : error CS2001: Source File 'x' could not be found"
All errors refer to Linked Files (aspx,cs,etc) located in other web applications projects located at a different deep in our code Branch (that's why all the '....\' at the beginning of the paths)
To me it looks like a problem with the file Length, I had the same problem a while ago when building the projects on our CI server using MSBuild, I was able to manage it by manipulating the project files before building them using a custom script without the need to move the branch around or reduce the deep of the projects, I didn't have to move anything, the important thing at the time it was that developers using Visual Studio 2010 could compile everything without problems. I learned by this that compiling/Building with MSBuild was different that with DevEnv/VS, and for example MSBuild didn't support building Setup projects and DevEnv did.
Since this is happening now with VS 2012/DevEnv 2012 , plus that VS 2012 doesn't support setup projects anymore (like msbuild), plus VS/DevEnv have the same problem with the file length, it looks like VS 2012 its finally using msbuild under the hood or are more tightly integrated, however I didn't find any article to confirm this.
Changing the branch structure/changing the deep of the projects it’s not an option right now due to several reasons (large code base, high number of projects, risk, timing, effort, etc.).
Does someone have an alternative solution or a fix for this issue in Visual Studio 2012?
Regards,
P.D.: BTW I already checked this post MSBuild error with linked files but like I said before changing the paths its not an option right now.

Try getting the Build Logs,
http://msdn.microsoft.com/en-us/library/vstudio/ms171470.aspx
it seems that csc task could not find the source file. One cause it you import the wrong file.
so you have to edit the project file via normal Text Editor.

I found a solution to this issue, when you linked the file, you relative path is recognized by msbuild and go back from there it become your path in a long path however you can change it in the project definition doing right click/unload the project/ and change the path from ../../../ to $(SolutionDir)/../.. until find the file to link, note: it's extend the character from 255 to 300 character.

Check that you have the latest version of the linked files from the other projects. Visual Studio will NOT automatically get them if they belong to another project.
Check that the linked paths are indeed correct. You can monitor what files VS.NET and MSBUILD are trying to access with the help of the SysInternals ProcMon tool (filter on process names and filter out all successes)
If you suspect that the path length is the problem (this will also be visible in the ProcMon tool), you can try to shorten them by linking to the absolute path (C:\X\Y\Z) instead of a relative path (......\Z). The location of the linked files can then remain unchanged.

My 2 cents to this problem... In my case, I had a file created in one project (i.e. ConfigModel) and I had a link to this file in another project but when I renamed the file ConfigModel in the first project to LoginModel for example, it didn't rename the link in the second project causing this error to occur.

I know that i did this question a while ago but for what is worth, The approach that we finally went for was:
Locating the files that were reported as too long.
Reduce the full path length of those files, by reducing the length of the name and/or
the length of the container folder or reducing the folder nesting
level. Therefore reducing the full path length.
Update the links of the changed files (re-linking) on the dependant projects.
This solved the problem with Visual Studio 2012 on developers workstations and on our CI/Deploy servers that used MSbuild.
For my scenario this approach was less risky,and implied less effort than moving complete projects/solutions to reduce their folder nesting level or reducing the folder names, and have to update all the references of the dependant project/solutions.

Ok, I hit this and solved it today. I found it by following a msdn tutorial (https://msdn.microsoft.com/en-us/library/ms379563%28v=vs.80%29.aspx) and here's the command that broke for me:
csc /t:library /out:MyCodeLibrary.dll simpleType.cs
Giving me the message
error CS2001: Source file 't:librabry' could not be found
Which worked after changing the original command to the following:
csc /target:library /out:MyCodeLibrary.dll simpleType.cs
I'm not sure why the short version of the /target flag causes this error, but I've not found anywhere else online noting this cause specifically so I wanted to record it here.

This problem arose for me when I reverted to an earlier version of a git repository. Apparently I didn't add the project file to the repo so when it reverted it didn't revert the project file also. What I did to clear it up was to exclude the missing .cs file from the project by clicking on the missing file in the project Explorer. It was easy to find since it was marked with a warning triangle. Then rebuild the entire solution.

Verify whether the files mentioned in the error do not exist in the corresponding folder.
If their non-existence is intentional, edit the .csproj files and remove the reference for those files.
Build again.

I inherited this issue from a project somebody else was working on, in my case was a .cs file supposed to be generated by an Entity Framework .tt template, but for some reason it wasn't, so the compiler was going all CS2001 about that. I had to update the template and manually run it, everything worked after that.

Related

How to fix Android Studio 1.0.2 copy bug?

Consider this scenario, I created a new project and made sure it compiles and runs. I now try to use Refactor->Copy or Refactor->Rename or Refactor->Move. The project starts spewing errors.
It might have something to do with a bug mentions at
https://code.google.com/p/android/issues/detail?id=56284
Quoting:
This bug still affects version 1.0.2. The OP discovered the details and posted them in his blog, but didn't bother to update this bug report.
The problem is caused by the fact that the following files (relative to the root of the project) contain the absolute path to the project:
$PROJECTNAME.iml
$MODULENAME/$MODULENAME.iml
.idea/gradle.xml
.idea/workspace.xml
Additionally, with the curious exception of the module .iml, the paths in these files have symlinks resolved, which defeats the purpose of using symlinks in project directories.
The priority on this issue is not 'small'. The presence of absolute paths in these files renders Android Studio completely unusable for collaborative projects.
In the past, I am able to just move around or rename the project folder and I can still open it without problem on AS, that is because it uses relative paths before.
My question is, how can I fix the project affected by this bug?

error FTK1013: could not find unicode byte order marker

What does this error mean:
Error 8 error FTK1013: could not find unicode byte order marker in the file
tracking log file: c:\Users\ASUS\documents\visual studio
2010\Projects\project\project\Debug\CL.write.1.tlog.
The tracking data is invalid. c:\Users\ASUS\documents\visual studio
2010\Projects\project\project\FileTracker project
.tlog files are created as the build goes, writing dependencies, command lines, etc, not anything directly in your control. You're not supposed to see that kind of error unless maybe your disk is full or you manage to launch multiple builds on the same project somehow.
Exit VS, delete the debug folder. Look around in task manager for stray processes or reboot.
Reopen the solution and try build, with some hope the problem just goes away for good.
If someone faced mentioned error you should know that it's VS2010 issue only.
It's already tested and checked. Be careful with following project names:
mt, link, midle, cl, bscmake, rc
In most cases you could just build your project again and buld process will be finished successfully, but if you want to avoid of this error at each RE-build(or first buid, or automatic build by some of control system) you have to rename your project.
Also described and discussed in:
MS Social thread "Error FTK1013: could not find unicode byte order marker in file tracking log file"
Delete the Debug folder in the Visual Studio project folder. Re-build.
I am sharing one workaround for this issue.
Disable /MP for the project(s). Set value "NO" in the "Multi-processor Compilation" setting under Configuration Properties > C/C++->general in the project property window. It worked for me.
Follow these 4 simple steps:
1) go in the Debug folder.
2) Search for the file.
3) Delete the file.
4) Build the project again.

The specified task executable "LC.exe" could not be run

I am developing a SharePoint 2013 solution using VS 2012, the solution has a licx file. I get a compile time error and a warning.
Error: The specified task executable "LC.exe" could not be run. The filename or extension is too long
Warning: The command-line for the "LC" task is too long. Command-lines longer than 32000 characters are likely to fail. Try reducing the length of the command-line by breaking down the call to "LC" into multiple calls with fewer parameters per call.
I have tried the lc.exe.config has <startup useLegacyV2RuntimeActivationPolicy="true">
I also tried moving the solution to "C:\", was earlier in the Projects folder.
I am still unable to resolve this error.
There is MS Support workaround:
when you build the project , delete the Licence file from the project
everytime you get this error , just delete the licence file
https://connect.microsoft.com/VisualStudio/feedback/details/779433/lc-exe-task-command-line-too-long
You will be able to save a lot on the path length by making a shortcut to the specific .NET version you use (in this case 4.5.2). Here are the steps;
run command line as Administator
Go to C:\ in command line
mklink /J net452 "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2"
Go to VisualStudio
Open project properties
Look into References tab
Click on "Reference paths" button and add path "C:\net452"
Rebuild project
Deleting licenses.licx file is not a solution. It will give you error at runtime if you are using third party control which need licenses.
LC.exe takes argument as licenses file with full path, if argument is too long, it throw error.
So keep the file name and path shorter length, it will compile and work.
Deleting licence file did not help me. I end up deleting the "licenses.licx" under the Solution Explorer -> Properties group
Surly that helps
This issue is fixed in VS2017 as per this GitHub checkin: https://github.com/Microsoft/msbuild/commit/e49717c727c3cab4db466bcb0a5abb624a8156bb
I believe the version is full release version is VS2017 Update 2.

Ogre3d Error: cannot open file OgreMain_d.lib

Error 2 error LNK1104: cannot open file 'OgreMain_d.lib' C:\Users\Owner\Documents\Code\C++\Test\ogrevcpp\ogrevcpp\LINK ogrevcpp
This is the error I get when trying to build an Ogre3D application (with steps followed from here).
I've followed everything to the T, yet I still get the error. It honestly shouldn't be happening. I've also followed everything from here.
Edit
What's happening is there are two different files, one is meant for release, the other is meant for debug. I need the one for debug mode to compile properly (which is OgreMain_d.lib).
Update
I figured out what the problem was - I was using the incorrect binaries; there was a few releases which were meant for Visual C++, and one which was meant for MinGW, along with a few other compilers. My apologies.
You need to check your library paths to make sure that the path where OgreMain_d.lib lives is part of the library path.
I guess the library for Debug mode is not present in the lib folder. Try putting two different libraries folder for each Assembly mode in Visual Studio. Go to ProjectProperties -> Configuration Properties -> Linker -> Additional Library Directories on Right hand. Make sure to check the Configuration Dropdown on the top.

How do I rename an entire project in VC++ 2005

I've got a really large project I made for myself and rece3ntly a client asked for their own version of it with some modifications. The project name was rather silly and my client wants the source so I figured it'd be best if I renamed all my files from
sillyname.h
sillyname.cpp
sillyname.dsp
etc..
Unfortunatly after I added everything back together I can't see any way to change the project name itself. Plus now I'm getting this error on compilation.
main.obj : error LNK2001: unresolved external symbol __imp__InitCommonControls#0
Debug/New_Name_Thats_not_so_silly.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
There has to be an easier way to change all this, right?
Here is a Step by Step on Steve Andrews' blog (he works on Visual Studio at Microsoft)
I haven't verified this, but I've done this a number of times and if my memory serves me right, you can actually use the search-and-replace functionality in VS2005 to rename all instances of the string "X" to "Y" in any type of file.
Then you need to close the solution and change the project (and any other file with the same name regardless of extension) file name(s).
You will obviously need to do a full rebuild afterwards.
I find it always annoying too, to do this manually.
So I tried some tools available by googling- two didn't work (VS C++ here), dunno, if they are more useful for C#.
The following tool worked good for me: I have used the trial version, but I will pay 39,- bucks for it. For me it is worth it. It has also a VS add-in. VS 2013 was not supported directly, at least not mentioned, yet, when I looked:
http://www.kinook.com/CopyWiz
In-place rename didn't work (access error), but "rename-while-copying" worked fine.
But I really wonder, if it is so difficult as some programmers claim. For most parts file renaming and a search&replace of all occurences in all text files in the project dir should be a quite easy and working approach. Maybe someone can contibute what shall be so difficult.
The rational part of my brain forbids the dreaming part to program an own tool- I am lucky ! :-)
You can simply rename the .vcproj or .dsp file and then either create a new workspace (sln dsw) and include the renamed project or simply chnage the name inside the sln file (it's just xml) I can't remember the format of the old workspace but it's still text.
You can either manually rename and reinclude all the .cpp of edit the project file and rename them in there.
sorry don't know of refactoring tool that will do all this but there probably is one.
I assume that in addition to the renamed set of files, you also still maintain a complete "parallel" set of the original files in some other directory, am I right?
Assuming you have both versions, what I would do is:
Get a file comparison tool like Beyond Compare or DiffMerge and compare the old SLN file and the new SLN file side-by-side. Also do this for each "proj" file and any other "config" type files.
It is possible to edit these files by hand. Usually looking at what is different between two copies will help illuminate what you should do to get the second one working.
You might as well start tinkering with the renamed project by hand, anyway, given that it already isn't working. You can't make it much worse. And: you might learn some handy tricks about the XML structure of these files.
Even if you do make small mistakes when hand-tweaking this files, I have repeatedly been very impressed by how Visual Studio handles things. Visual Studio will usually tell you exactly where you got it wrong.

Resources