Since upgrading to VS 2015, my team has experienced random quirky things which I'm sure are being worked out at Microsoft right now. One pretty annoying one is that we seem to lose project references, especially after branching. I began to work on a new branch of our solution yesterday only to find out that types were unrecognized and namespace usings were being cited as unnecessary (because they were for the types that had suddenly become unrecognized).
The references in the project did not show any icons indicating a problem with the reference, but just to see if it would work, I removed and re-added a project reference, which caused its types to be recognized once more.
This, of course, updated the project file, so I looked to see what changes had been made. The only difference between the project that could not detect the reference and the one that now can is that the alpha characters in the GUID had been changed from lower case to upper case. For example:
Old, broken reference:
<ProjectReference Include="path/redacted">
<Project>{95d34b2e-2ceb-499e-ab9e-b644b0af710d}</Project>
<Name>Project.Name.Redacted</Name>
</ProjectReference>
New, fixed reference:
<ProjectReference Include="path/redacted">
<Project>{95D34B2E-2CEB-499E-AB9E-B644B0AF710D}</Project>
<Name>Project.Name.Redacted</Name>
</ProjectReference>
I'm looking for the reason this is happening and how I might fix it without having to manually remove and re-add references all over the place (and without having to convert all the project file GUIDs to upper case).
I should note that these "broken" references are not breaking the build, and that they only show up in the Error List as IntelliSense error, not build errors. So, the references aren't really broken, they've just broken IntelliSense (which is arguably worse?!).
TL;DR
Visual Studio isn't entirely consistent about how it assigns GUIDs to projects or how it specifies those GUIDs in project references. I was able to resolve the problem by using upper case GUIDs with braces for ProjectGuid elements and lower case with braces for Project elements (in references).
Background
We have a large solution (60+ C# projects), and were having regular issues with solution Rebuild as incorrect build order would cause failure to resolve referenced projects that had not yet been built (but should have been). Build Dependencies and Build Order appeared correct. MSBuild batch build worked fine, it was only a problem when rebuilding from Visual Studio.
Forcing all project GUIDs to upper case with braces and all project reference GUIDs to lower case with braces fixed the problem. This is usually how Visual Studio generates these GUIDs, but not always.
Doing some investigation in a brand new test solution, it turns out that:
Generated GUIDs for console application projects are upper case with braces.
Generated GUIDs for class library projects are initially lower case with no braces.
If a new project reference is added a class library project with a lower case GUID, then not only is the reference GUID added, but the project GUID is converted to upper case with braces.
If a copy of a class library project is made and then added to the solution then its GUID is replaced with a new one that uses upper case and braces. (But if a copy is made and its GUID manually removed, Visual Studio does not insert a replacement GUID into the .csproj file.)
Project references GUIDs are usually use lower case and braces, but somehow our project had accumulated a bunch of upper case GUID references.
GUIDs in the .sln always use upper case and braces.
I was able to fix our broken rebuild by replacing the reference GUIDs with either all upper case or all lower case -- it's something about the mix of upper and lower case that was giving Visual Studio problems (perhaps case-sensitive string keys in a dictionary somewhere?) Since Visual Studio normally adds references with lower case GUIDs, that is the option I chose to go with.
Regex Search & Replace
To fix this, I used Notepad++ regex-based search and replace in files to force all ProjectGuids in .csproj files to be upper case with braces (the default for console applications, and the style Visual Studio will apply after adding any project reference to the project):
Find what: (<ProjectGuid>)\{?([0-9a-f-]+)\}?(</ProjectGuid>)
Replace with: \1{\U\2}\E\3
Search in: *.csproj
Be sure to turn on regular expression search, and turn off match case. And don't search all files, or you may make changes you don't want, for example in *.xproj files, as noted by #AspNyc. (See this answer for additional info on use of regular expressions for changing case.)
I then replaced all references to projects to use lower case with braces (which is what Visual Studio usually does):
Find what: (<Project>)\{?([0-9a-f-]+)\}?(</Project>)
Replace with: \1{\L\2}\E\3
Search in: *.csproj
Having made these changes, Visual Studio solution rebuild now works reliably. (At least until next time rogue upper case reference GUIDs sneak into our project.)
I suffered a similar issue when updating VS2017 v15.7 to v15.9.
The answer for me was to close down VS, clear out the hidden .vs folder in my solution's root directory and restart VS.
There's a bug in the projectsystem it seems. This powershell will loop over projects and make all references upper case:
#FixGuids
get-childitem -recurse | ?{ #('.sln', '.csproj', '.vbproj') -contains $_.Extension } | %{
[regex]::Replace((gc -raw $_.FullName), '[{(]?[0-9A-Fa-f]{8}[-]?([0-9A-Fa-f]{4}[-]?){3}[0-9A-Fa-f]{12}[)}]?', { return ([string]$args[0]).ToUpperInvariant() }) |
Out-File $_.FullName -Encoding "UTF8
}
It's quite simplistic. If you rely on guids in your projects for something other than references, you may want to turn it into something more intelligent.
In order to use the answer in a git hook, I had to convert it to sed's regex syntax:
sed -r "s/(<Project>\{?)([0-9A-F-]+)(\}?<\/Project>)/\1\L\2\E\3/g" sample.csproj
Maybe someone finds this useful.
Today in visual studio 2019 (16.2.2) I was encountering build system issues where projects were being unnecessarily (and repeatedly) rebuilt whenever I initiated the building of my solution.
(None of the usual steps resolved the build issues, eg deleting the ".vs" folder, or deleting "bin" and "obj" directories, etc).
At first it appeared to be related to the character-casing of guids, because I was able to get the problem to go away by editing the guids and saving the project. However that was a red-herring ... I was unwittingly fixing the problem by changing the timestamps of all my csproj files. The build system seemed a lot happier after those timestamps were updated, and it stopped the annoying behavior (continuously attempting to rebuild projects that had already been built.)
The character casing of the guids didn't end up being the problem at all. As far as I can tell, VS 2019 is ok with both upper- and lower-case guids. They can even mismatch the source project, based on my experimentation (eg. the original source project can use uppercase and referencing projects can use lowercase).
If it is helpful to anyone, below is a powershell that will let you adjust the write-time of all csproj files under a path. This will be another trick I use whenever the msbuild system is misbehaving in visual studio.
$datenow = get-date
$files = Get-ChildItem -path "C:\Data\Workspaces\LumberTrack\" -recurse | where { $_.PSIsContainer -eq $false}
foreach ($file in $files)
{
if ($file.Extension -eq ".csproj")
{
Set-ItemProperty $file.FullName LastWriteTime $datenow
Write-Output $file.FullName
}
}
}
Related
On a certain solution the "Remove and Sort Usings" option does not work.
It sorts the Usings correctly, but does not remove any unnecessary ones.
The IDE is flagging the unused ones correctly, but it can't seem to remove them.
No errors or messages are displayed anywhere, it sorts and behaves like it has completed successfully, but the unnecessary Usings remain and are still flagged by Intellisense as such.
I have verified that in a different solution it does work, so it is not my VS2019 install.
And I don't have any plugins installed (like Resharper) that could conflict.
Have also tried clean and rebuild in case it needed an error-free compilation to work with.
Any ideas what could be different/special about a certain solution that would prevent the remove functionality?
I have found another thing which causes this issue.
For me, I discovered it was only happening in 1 particular project in a solution.
After comparing the non-working csproj to a working one, I determined that the difference was the Warning Level.
The non-working one was set to 1.
Resetting this to the default 4 allows the Remove and Sort Usings function to work as expected.
I found the cause, and it's an annoying one!
There is a custom ruleset specified for static analysis of the projects, and that had both CS8019 and IDE0065 (Unnecessary using directive) unselected.
On selecting these the remove unused usings command worked again.
Thanks to other answers for suggestions.
I had the same problem and figured out what was wrong. In your Tools|Options|Text Editor|C#|Advanced look for theses settings:
HTH.
Any ideas what could be different/special about a certain solution
that would prevent the remove functionality?
This is quite a strange behavior. You could try these suggestions:
1) close VS Instance, delete .vs hidden folder, bin, obj folder.
2) clean vs component caches under C:\Users\xxx\AppData\Local\Microsoft\VisualStudio\16.0_xxxx(every this folder)\ComponentModelCache
3) use devenv /safemode to start VS IDE, open your project and then test again.
4) If your project is an old project which means that the project structure is a bit different from VS2019, please try to create a new vs2019 project and then migrate its content into the new project.
In addition, if these do not work, you can try this link's function to run Code Cleanup command with remove unused usings.
Short Version
I found myself losing alot of time renaming + including files in my Xamarin.Forms Projects because any change from Upercase to Lowercase (or vice versa) only in the files, will result in no change what so ever in the Project file, so i have a few questions:
Is there an option in Visual Studio that makes it take into account file renaming from Upercase to Lowercase? (See Edit Below)
What's the best way of changing alot of files from Upercase to Lowercase without delete/re-adding them?
Is renaming the file includes in the .csproj directly a Good Practice? if not, what is the best for this kind of scenarios?
Longer Version + Adicional Info
I had to include over 2000 images (Android + iOS and their respective sizes). So i started copying the files into the correct directory and include them in the Mobile Projects, the problem came when i already included the files in the project and some of the files had Uppercase letters that i haven't noticed before, so i made changes by hand to all the files, when i noticed that those changes weren't reflected in the Solution Explorer/Project File, i tried manually and got this error:
Edit: It seems this issue was apparently resolved in VS2019 arround v.16.1, but only if the file wasn't renamed externally. Since i did that i got this warning. This anwsers my first question.
And one solution that i found was renaming like: Foo.png > fooo.png > foo.png
But that would be exponentialy time-consuming by the number of files i had to edit, so i made this piece of code:
string filepath = #"C:\Users\(...)";
DirectoryInfo d = new DirectoryInfo(filepath);
foreach (var file in d.GetFiles("*.png", SearchOption.AllDirectories))
{
if (file.Name.Any(char.IsUpper))
{
File.Move(file.FullName, file.FullName.Replace(file.Name, file.Name.ToLower()));
}
}
What it does is basically create a new file but with Lowercase, that means i still have to Remove the old References and Include the new Files. This doesn't seem right since a simple rename would do.
What's my go to option here?
Windows as operating system is ascendant of the operating system where there was no difference in lower and uppercase. As such at today's state Windows treats the files with same letters as the same though technically it can remember and display lower and upper cases in file names.
Overall it means your request is not natural in Windows. Maybe someone can provide you with some hack, but if you want to resolve this problem quickly move your project to the Mac where this works differently at the operating system level, perform your operation in Visual Studio for Mac and then you can continue to use Windows if you prefer.
EDIT: Actually I can tell you one hack for Windows. First rename file to whatever you want (like add 1 at the end) and then rename it to the desired file name. It will work properly.
I had the same issue. In my case the files were in the .csproj (Project File) with lowercase name. Removing the affected lines from .csproj fixed the problem.
In Visual Studio 2019 -
Right click on the project name in Solution Explorer -> select "Edit Project File"
Find the offending file under ItemGroup, you can either remove the line or edit the filename. I have not had any side effects by removing the file as I know what I am doing, your mileage might differ.
Just incase cut and paste the delete or rename before hand in Notepad in case you want to go back, Ctrl-z works too :)
Since upgrading to VS 2015, my team has experienced random quirky things which I'm sure are being worked out at Microsoft right now. One pretty annoying one is that we seem to lose project references, especially after branching. I began to work on a new branch of our solution yesterday only to find out that types were unrecognized and namespace usings were being cited as unnecessary (because they were for the types that had suddenly become unrecognized).
The references in the project did not show any icons indicating a problem with the reference, but just to see if it would work, I removed and re-added a project reference, which caused its types to be recognized once more.
This, of course, updated the project file, so I looked to see what changes had been made. The only difference between the project that could not detect the reference and the one that now can is that the alpha characters in the GUID had been changed from lower case to upper case. For example:
Old, broken reference:
<ProjectReference Include="path/redacted">
<Project>{95d34b2e-2ceb-499e-ab9e-b644b0af710d}</Project>
<Name>Project.Name.Redacted</Name>
</ProjectReference>
New, fixed reference:
<ProjectReference Include="path/redacted">
<Project>{95D34B2E-2CEB-499E-AB9E-B644B0AF710D}</Project>
<Name>Project.Name.Redacted</Name>
</ProjectReference>
I'm looking for the reason this is happening and how I might fix it without having to manually remove and re-add references all over the place (and without having to convert all the project file GUIDs to upper case).
I should note that these "broken" references are not breaking the build, and that they only show up in the Error List as IntelliSense error, not build errors. So, the references aren't really broken, they've just broken IntelliSense (which is arguably worse?!).
TL;DR
Visual Studio isn't entirely consistent about how it assigns GUIDs to projects or how it specifies those GUIDs in project references. I was able to resolve the problem by using upper case GUIDs with braces for ProjectGuid elements and lower case with braces for Project elements (in references).
Background
We have a large solution (60+ C# projects), and were having regular issues with solution Rebuild as incorrect build order would cause failure to resolve referenced projects that had not yet been built (but should have been). Build Dependencies and Build Order appeared correct. MSBuild batch build worked fine, it was only a problem when rebuilding from Visual Studio.
Forcing all project GUIDs to upper case with braces and all project reference GUIDs to lower case with braces fixed the problem. This is usually how Visual Studio generates these GUIDs, but not always.
Doing some investigation in a brand new test solution, it turns out that:
Generated GUIDs for console application projects are upper case with braces.
Generated GUIDs for class library projects are initially lower case with no braces.
If a new project reference is added a class library project with a lower case GUID, then not only is the reference GUID added, but the project GUID is converted to upper case with braces.
If a copy of a class library project is made and then added to the solution then its GUID is replaced with a new one that uses upper case and braces. (But if a copy is made and its GUID manually removed, Visual Studio does not insert a replacement GUID into the .csproj file.)
Project references GUIDs are usually use lower case and braces, but somehow our project had accumulated a bunch of upper case GUID references.
GUIDs in the .sln always use upper case and braces.
I was able to fix our broken rebuild by replacing the reference GUIDs with either all upper case or all lower case -- it's something about the mix of upper and lower case that was giving Visual Studio problems (perhaps case-sensitive string keys in a dictionary somewhere?) Since Visual Studio normally adds references with lower case GUIDs, that is the option I chose to go with.
Regex Search & Replace
To fix this, I used Notepad++ regex-based search and replace in files to force all ProjectGuids in .csproj files to be upper case with braces (the default for console applications, and the style Visual Studio will apply after adding any project reference to the project):
Find what: (<ProjectGuid>)\{?([0-9a-f-]+)\}?(</ProjectGuid>)
Replace with: \1{\U\2}\E\3
Search in: *.csproj
Be sure to turn on regular expression search, and turn off match case. And don't search all files, or you may make changes you don't want, for example in *.xproj files, as noted by #AspNyc. (See this answer for additional info on use of regular expressions for changing case.)
I then replaced all references to projects to use lower case with braces (which is what Visual Studio usually does):
Find what: (<Project>)\{?([0-9a-f-]+)\}?(</Project>)
Replace with: \1{\L\2}\E\3
Search in: *.csproj
Having made these changes, Visual Studio solution rebuild now works reliably. (At least until next time rogue upper case reference GUIDs sneak into our project.)
I suffered a similar issue when updating VS2017 v15.7 to v15.9.
The answer for me was to close down VS, clear out the hidden .vs folder in my solution's root directory and restart VS.
There's a bug in the projectsystem it seems. This powershell will loop over projects and make all references upper case:
#FixGuids
get-childitem -recurse | ?{ #('.sln', '.csproj', '.vbproj') -contains $_.Extension } | %{
[regex]::Replace((gc -raw $_.FullName), '[{(]?[0-9A-Fa-f]{8}[-]?([0-9A-Fa-f]{4}[-]?){3}[0-9A-Fa-f]{12}[)}]?', { return ([string]$args[0]).ToUpperInvariant() }) |
Out-File $_.FullName -Encoding "UTF8
}
It's quite simplistic. If you rely on guids in your projects for something other than references, you may want to turn it into something more intelligent.
In order to use the answer in a git hook, I had to convert it to sed's regex syntax:
sed -r "s/(<Project>\{?)([0-9A-F-]+)(\}?<\/Project>)/\1\L\2\E\3/g" sample.csproj
Maybe someone finds this useful.
Today in visual studio 2019 (16.2.2) I was encountering build system issues where projects were being unnecessarily (and repeatedly) rebuilt whenever I initiated the building of my solution.
(None of the usual steps resolved the build issues, eg deleting the ".vs" folder, or deleting "bin" and "obj" directories, etc).
At first it appeared to be related to the character-casing of guids, because I was able to get the problem to go away by editing the guids and saving the project. However that was a red-herring ... I was unwittingly fixing the problem by changing the timestamps of all my csproj files. The build system seemed a lot happier after those timestamps were updated, and it stopped the annoying behavior (continuously attempting to rebuild projects that had already been built.)
The character casing of the guids didn't end up being the problem at all. As far as I can tell, VS 2019 is ok with both upper- and lower-case guids. They can even mismatch the source project, based on my experimentation (eg. the original source project can use uppercase and referencing projects can use lowercase).
If it is helpful to anyone, below is a powershell that will let you adjust the write-time of all csproj files under a path. This will be another trick I use whenever the msbuild system is misbehaving in visual studio.
$datenow = get-date
$files = Get-ChildItem -path "C:\Data\Workspaces\LumberTrack\" -recurse | where { $_.PSIsContainer -eq $false}
foreach ($file in $files)
{
if ($file.Extension -eq ".csproj")
{
Set-ItemProperty $file.FullName LastWriteTime $datenow
Write-Output $file.FullName
}
}
}
I have stumbled into an issue that is really annoying.
When I debug my software, everything runs OK, but if I hit a breakpoint and edit the code, when I try to continue running I get an error:
Metadata file 'XYZ' could not be found
After looking around for a while, I found some a similar issues, but they were all regarding a build failure, which is not my case (this happens only after edit-continue).
What I have tried so far:
My code is compiling and running.
I cleaned the solution and restarted VS.
I made sure that the missing file's project is being build for the configuration I am running (in configuration manager).
I manually built the missing file's project.
Some extra info:
It does not matter what I change, still get the same error (the change is not related to the missing file).
This happens also when I pause and continue (not only breakpoints)
I am running the project using a custom configuration (configuration manager...). When I run it using the default Debug configuration the error does not occur.
Any ideas?
Eventually what solved the issue was:
Clean every project individually (Right click> Clean).
Rebuild every project individually (Right click> Rebuild).
Rebuild the startup project.
I guess for some reason, just cleaning the solution had a different effect than specifically cleaning every project individually.
Edit:
As per #maplemale comment, It seems that sometimes removing and re-adding each reference is also required.
Update 2019:
This question got a lot of traffic in the past, but it seems that since VS 2017 was released, it got much less attention.
So another suggestion would be - Update to a newer version of VS (>= 2017) and among other new features this issue will also be solved
As far as I can tell, this happens when the project dependencies gets messed up for whatever reason (whilst all the inter-project references are still intact). For many cases, it is NOT a code issue. And for those who have more than a few projects, going through them one at a time is NOT acceptable.
It's easy to reset project dependencies -
Select all projects and right click unload
Select all projects and right click reload
Rebuild solution
For those who have an issue in their code or some other issue that's causing this problem you'll obviously have to solve that issue first.
One possible reason could be you have upgraded the some of your projects (in the solution) to higher version e.g. from .NET 4.0 to 4.5 This happened in my case when I opened the solution in VS 2013 (originally created using VS 2010 and .NET 4.0). When I opened in VS 2013 my C++ project got updated to .NET 4.5 and I started to see the problem.
Generally this kind of error comes with human mistakes like if we change the namespace in some improper way, or changing folder names from explorer for current project etc, where compiler is unable to detect sometimes.
I came across the same error, to resolve which I tried few steps. Please follow all the steps :
Clean whole Solution
Right Click on every Project in your solution , Go to Properties and make your Default namespace as well as Default assembly name same as in your code (i.e namespace before class name)
Check Folder names for each project by going through the explorer(Where your project solution is). If not matching with your project names, make it similar (Like step 2) to them.
Remove all your references from each project relevant to another of same solution, and add it again.
In Your Project Solution folder, you will find Visual c# Project file. Right click and open with Notepad. In your initial lines you would find for lines for every project like below:
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "**Client**", "**Client** \ **Client**.csproj", "{4503E259-0E3B-414A-9074-F251684322A5}"
EndProject
Check again Foldernames (I have highlighted in BOLD) and make it similar to what you did in step 2.
Clean the whole solution again
Build The Solution (If doesn't work try building individual after cleaning again)
Make sure all your dependent projects are using the same .Net Framework version. I had the same issue caused by a dependent project using 4.5.1, while all others were using 4.5. Changing the project from 4.5.1 to 4.5 and rebuilding my solution fixed this issue for me.
XYZ couldn't be found because is not built yet....
Right click on the solution and check Project Dependencies, the Project Build Order should also change according to the dependencies that have been set.
The only thing that worked for me was to delete the Solution User Options (.suo) file. Note that, this is a hidden file.
To locate this file, close your Virsual studio and search for .suo from the file explorer within your project.
PS: a new .suo file will be created again when you rebuild your project and hopefully this newly created one wont give you issues.
I hope that helps someone get rid of this anoying error :).
I had this problem for days! I tried all the stuff above, but the problem kept coming back. When this message is shown it can have the meaning of "one or more projects in your solution did not compile cleanly" thus the metadata for the file was never written. But in my case, I didn't see any of the other compiler errors!!! I kept working at trying to compile each solution manually, and only after getting VS2012 to actually reveal some compiler errors I hadn't seen previously, this problem vanished.
I fooled around with build orders, no build orders, referencing debug dlls (which were manually compiled)... NOTHING seemed to work, until I found these errors which did not show up when compiling the entire solution!!!!
Sometimes, it seems, when compiling, that the compiler will exit on some errors... I've seen this in the past where after fixing issues, subsequent compiles show NEW errors. I don't know why it happens and it's somewhat rare for me to have these issues. However, when you do have them like this, it's a real pain in trying to find out what's going on. Good Luck!
Well, my answer is not just the summary of all the solutions, but it offers more than that.
Section (1):
In general solutions:
I had 4 errors of this kind (‘metadata file could not be found’) along with 1 error saying 'Source File Could Not Be Opened (‘Unspecified error ‘)'.
I tried to get rid of ‘metadata file could not be found’ error. For that, I read many posts, blogs etc and found these solutions may be effective (summarizing them over here):
Restart VS and try building again.
Go to 'Solution Explorer'. Right click on Solution. Go to Properties. Go to 'Configuration Manager'. Check if the checkboxes under 'Build' are checked or not. If any or all of them are unchecked, then check them and try building again.
If the above solution(s) do not work, then follow sequence mentioned in step 2 above, and even if all the checkboxes are checked, uncheck them, check again and try to build again.
Build Order and Project Dependencies:
Go to 'Solution Explorer'. Right click on Solution. Go to 'Project Dependencies...'. You will see 2 tabs: 'Dependencies' and 'Build Order'. This build order is the one in which solution builds. Check the project dependencies and the build order to verify if some project (say 'project1') which is dependent on other (say 'project2') is trying to build before that one (project2). This might be the cause for the error.
Check the path of the missing .dll:
Check the path of the missing .dll. If the path contains space or any other invalid path character, remove it and try building again.
If this is the cause, then adjust the build order.
Are you using a database code generation tool like SQLMETAL in your project?
If so, you may be facing a pluralized to unpluralized transition issue.
In my case, I have noted that some old pluralized (*) table names (upon which SQLMETAL adds, by default, an "s" letter at the end) table references to classes generated by SQLMETAL.
Since, I have recently disabled Pluralization of names, after regerating some database related classes, some of them lost their "s" prefix. Therefore, all references to affected table classes became invalid. For this reason, I have several compilation errors like the following:
'xxxx' does not contain a definition for 'TableNames' and no extension method 'TableNames' accepting a first argument of type 'yyyy' could be found (are you missing a using directive or an assembly reference?)
As you know, I takes only on error to prevent an assembly from compiling. And that is the missing assemply is linkable to dependent assemblies, causing the original "Metadata file 'XYZ' could not be found"
After fixing affected class tables references manually to their current names (unpluralized), I was finnaly able to get my project back to life!
(*) If option Visual Studio > Tools menu > Options > Database Tools > O/R Designer > Pluralization of names is enabled, some SQLMETALl code generator will add an "s" letter at the end of some generated table classes, although table has no "s" suffix on target database. For further information, please refer to http://msdn.microsoft.com/en-us/library/bb386987(v=vs.110).aspx
Hope it helps!
I had this error come up. I followed all of the solutions here but nothing worked. I was using Visual Studio 2013 Professional. I couldn't get the individual project rebuilds to work and I finally figured out there was a circular dependency in my references. Visual Studio does a pretty good job normally of warning you if you are adding a reference to something that references back, but for some reason it didn't in this instance. I added a reference to a project that referenced the project I was working on - and it accepted it. VS bug perhaps?
My 5 cents.
This problem started after a solution wide clean.
I managed to get the problem to go away by setting the Active Solution configuration in: Build -> Configuration manager to release. Then build and set it back to debug again. The build succeeded after that.
Close VS, locate and remove the 'packages' folder from outside of visual studio. Restart VS and build -> all dependencies are reinstalled
Visual Studio 2019 Community 16.3.10
I had similar issue with Release build. Debug build was compiling without any issues.
Turns out that the problem was caused by OneDrive. Most likely one could experience similar issues with any backed-up drive or cloud service.
I cleaned everything as per Avi Turner's great answer.
In addition, I manually deleted the \obj\Release -folder from my OneDrive folder and also logged to OneDrive with a browser and deleted the folder there also to prevent OneDrive from loading the cloud version back when compiling.
After that rebuilt and everything worked as should.
this happens because of the difference of names in the folder name and namespace name. If u create a namespace in a certain name , and later you rename it the namespace will have the old name itself. And the compilation will take the old path to find the .dll and .exe file . To avoid this open the .csproj file of each namespace with a text file , and find the old path in the file.
remove this, clean and rebuild the solution. This worked for me. I spent an entire day working on this problem.
I had this and managed to fix it using this SO answer:
Metadata file '.dll' could not be found
I had to uncheck all of the boxes, click Apply, reenable all of the checkboxes and then click apply again, but it fixed the problem.
I just ran into this issue and after an hour of screwing around realized I had added an aspx file to my product that had the same name as one of my Linq-To-Sql classes.
Class and Page where "Queue".
Changed the page to QueueMgr.aspx and everything built just fine.
For a new build, it could be that some dependencies aren't installed. For me it was Crystal Reports.
It happens when one project dll is failing and that is referenced by number of projects. So first fix it and then Build individuals.
I ve had this problem and it has started after importing our solution to TFS as a new project.I came across this topic and found a quick solution with some inspiration from your answers.
All i needed to do is to rebuild the project thats supposedly lost its metadata file and voila , problem solved.
There's also one another silly reason which you should check with patience... as it occurred to me after wasting 4hours searching for answers:
The story to me was that I accidentally changed a small line of code among thousands of c# class files and then trying to rebuild the solution. As you could imagine, I ended up with 40+ meta data file missing errors and with 1 compilation error among them -- which I didn't check carefully, purely thinking all errors were the same!
after 4 hours searching and then accidentally double checking my error list, I found that silly code error, fixed it, compiled, and then error disappeared.
Not a good answer to your problem, but do hope my case wasn't same to yours.
I had the same problem. In my case I had by mistake I had set all the projects apart from the project with the main method as console application.
To resolve I went to every project other than the one with main function and right click> properites > output type > class library
it was happened to me because I've a strange clash in the namespaces:
I had
AssemblyA
with namespace
AssemblyA.ParentNamespace
witch defines ClassA
and in the same assembly another namespace with name
AssemblyA.ParentNamespace.ChildNamespace
witch defines a different ClassA (but with the same name)
I had then in AssemblyA.ParentNamespace IInterfaceB witch had a method that in the beginning returns IEnumerable and a ClassB witch implements IInterfaceB
I had later modified the method in ClassB to return IEnumerable but I've forgot to update the IInterfaceB definition, so the method there was still returning IEnumerable
the fun fact was that the solution still complile if I did a rebuild all, but the tests witch refers AssemblyA didsn't work and returns the "Metadata file could not be found"error.
updating InterfaceB to correctly return IEnumerable as its implementor ClassB did solved the problem, unfortunately the error message was vague and also the fact that the compilation worked makes me suppose that maybe there is something to fix in the compiler
A coworker was running into this problem and the cause was eluding us. Eventually we realized that the project directory (and therefore the path to the NuGet packages) contained %20 (thanks, some Git gui tool which shall not be named) and the error messages showed that the compiler was looking for an very similar-looking path but one which had to %20, rather a space. Apparently something in the build system somewhere performs HTML-decoding on local filesystem paths.
Renamed the working copy directory and everything started working.
I had this issue too.
It started after I did a little folder tidying in my project.
I then tried to compile and got many duplicate class errors. (despite them not being duplicated. I think the linking was just out of wack)
Upon checking these, the errors would all disappear leaving only the "Metadata file ...debug\application.exe could not be found" error.
I solved this by looking in the build output window to find which classes were duplicated.
I would then right click the class name and "go to definition".
there will be two definitions to select from, open them both, the second definition will seem to open the same file again, however the second one will identify as the error source(red underline).
Delete all the code out of the file and save(This will not effect your actual file).
This should now compile correctly.
Ensure that there are no spaces in the path to your project...
I am using Windows 10 with Visual Studio Community 2019 and I was cloning a multi project solution as it was from a GIT repo. I was having this error with all other dependencies in the solution along with a E_POINTER error. Its path, inherited from GIT, had spaces like C:/repos/MY PROJECT NAME/ ...
I deleted it, cloned it again and make sure that its path contained no spaces like C:/repos/MY_PROJECT_NAME/ ...
That fixed my problem.
I had same issue too.
In my case, I recently add an internal class to somewhere in project. One of the dependencies in solution has same class name and both of them are added correctly to references.
I changed my last activity and rebuild, it works.
Be sure that your compiler messages are valid. In my case I catch reference error from there, not listed as an error in Error List.
So, as the title reads, I have a VS2010 solution with ~50 projects in it right now. If I make a change to a "top level" project that nothing references then VS still rebuilds all 50 projects. I'm running Visual Studio 2010 Ultimate without any add-ons. I am using ILMerge to consolidate all of the projects into a single file.
I have verified this by checking the time stamps of the lower level dlls and see that they are indeed rebuilt even though their code wasn't touched.
I've read all responses and comments for:
Visual Studio 2008 keeps rebuilding
Visual studio keeps building everything
Strange VS2010 build glitch occurs in my solution
Reasons for C# projects to rebuild in Visual Studio
But most of them just offer suggestions on unloading projects to speed up build times but nothing concrete as to a fix. I'm trying to figure out why VS thinks these dependent projects need to be rebuilt when they don't and fix it.
I've turned on 'Tools > Options > Projects and Solutions > Build and Run > Only build startup projects and dependencies on run' but with no effect.
Also, if I just rebuild a "mid-level" project that only has 8 (in)direct dependencies then it still builds all 8 projects even though ILMerge isn't invoked and none of the dependent projects have been modified.
Thank you everyone for any insight you may be able to provide.
Added
To test some of the suggestions I created a new WinForms project from scratch. I then created two new projects inside that solution. I copied all of the code and resources (not project file) from my two 'lowest level' projects into the two brand new projects (I did this by dropping the files and folders from Explorer onto the project in Visual Studio).
The lowest project, let's call it B, did not reference any other project. The next project, A, referenced B only. So once I added the required .NET and external assembly references to the projects then the solution would build.
I then had my new WinForm project reference A and did a full build. So the ref chain is:
WinForm -> A -> B
I then modified WinForm only and did a standard build (F6). As before, Visual Studio rebuilt all three projects.
After some systematic eleminiation of source files in project B I found that if I removed my Resources.Designer.cs and Resources.resx (and commented out the code that made use of the .Properties.Resources object of those resources) then a modification of WinForm would no longer rebuild the entire solution and would only rebuild WinForm.
Adding the Resources.resx and Resources.Designer.cs back to project B (but leaving the referenced code commented out so that nothing was making use of the resources) would re-introduce the full build behavior.
To see if perhaps my resource files were corrupted, I deleted them again and then created a new one (via Project Properties -> Resources) and re-added the same resource as before, which was a single Excel file. With this setup the full rebuild would still occur.
I then removed the single resource, but left the resource file in project B. Even with no resources added, but the resource file still in the project, the full (unneeded) rebuild would occur.
It appears that just having a resource file added to a (.NET 3.5) project will cause Visual Studio 2010 to always rebuild that project. Is this a bug or intended/expected behavior?
Thanks all again!
Open Tools - Options, select Projects and Solutions - Build and Run in tree, then set "MSBuild project build output verbosity" to Diagnostic.
This will output the reason for building a project, i.e.
Project 'ReferencedProject' is not up to date. Project item
'c:\some.xml' has 'Copy to Output Directory' attribute set to 'Copy
always'.
or
Project 'MyProject' is not up to date. Input file
'c:\ReferencedProject.dll' is modified after output file
'c:\MyProject.pdb'.
In this case the fix is to copy some.xml only if newer.
Pre and post build events can trigger build as well.
While I don't think this is a fix, it is a workaround that has worked for my situation...
I originally had about 5 projects out of 50 that contained a Resources section. These projects would always be rebuilt and thus anything that they depended on would also be rebuilt. One of those 5 projects was a "base" level library that 48 of the other projects referenced, thus 96% of my project would be rebuilt every time even if it didn't need it.
My workaround was to use dependency injection, interfaces, and a dedicated "Resources" project. Instead of having those 5 projects reference their own Resources object, I created an interface in each project that would supply the desired resources. Then, the classes that needed those resources would require that interface be passed in during their creation in the constructor (constructor injection).
I then created a separate "Resources" project that had an actual Resources section like normal. This project only contained the resources themselves, and a class for each interface that was needed to provide those resources via an interface. This project would reference every other project that had a resource dependency and implement the interface that the project needed.
Finally, in my "Top Level" project which nothing referenced (and where the exe was actually built and my composition root lives) I referenced the "Resources" project, wired up the DI, and away we went.
This means that only two projects (the "Resources" and the "Top Level") will be rebuilt every time, and if I do a partial build (Shift-F6) then they won't get rebuilt at all.
Again, not a great work around, but with 48 projects being built every time a build would take about 3 minutes, so I was losing 30 to 90 minutes a day with needless rebuilds. It took awhile to refactor, but I think it was a good investment.
Here is a simplified diagram. Note that the dependencies from Main.exe to Proj1 and Proj2 are not shown in order to reduce clutter.
With this design, I can do a build of Proj1 or Proj2 without triggering a full rebuild, since they don't have any dependencies on a Resources section. Only Main knows about the Resources implementation.
This happens when a project has a file that doesn't really exist.
The project can't determine if the file was changed (because it's not there) so it rebuilds.
Simply look at all the files in the project, and search for the one that doesn't have an expandable arrow near it.
I had the same issue in VS 2015.
What did the trick for me is:
One project was referencing itself copy in some other project bin (magic, yes). This kind of stuff could be found when switching to diagnostic build output (in build options) and then trying to build projects one by one from the top of projects hierarchy - if you see the project that rebuilds even if nothing has been changed then see it's references.
I've changed all "copy always" files in all projects to "copy if newer". Basically, in all .csproj files replace <CopyToOutputDirectory>Always</CopyToOutputDirectory>
to <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Then I've disabled NTFS tunneling as described in this article with this powershell script:
New-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "MaximumTunnelEntries" -Value 0 -PropertyType "DWord"
After that I needed on rebuild and it seems working for now.
In my case the culprit was "Copy Local" setting of a referenced dll set to true and "Copy to Output Directory" setting a file set to Copy always.
For .Net Core Projects, all solutions above are not working.
I've found the solution. In case you are using Visual Studio 2019:
Build the solution twice
Turn on Tools -> Options -> Projects and Solutions -> SDK-Style Projects -> Logging Level -> Verbose
Clear the output window
Build your start project
Inspect the output window. All the string starting with FastUpToDate
You will find some project items that are making your project not up to date.
Fix these issues and try again from step 1. If your fixes are correct, you will achieve Build: 0 succeeded, 0 failed, {n} up-to-date, 0 skipped in the last string of build output.
The MSBuild team is collecting documentation about investigating build incrementality issues here:
https://github.com/Microsoft/MSBuild/wiki/Rebuilding%20when%20nothing%20changed
UPDATED LINK: https://github.com/dotnet/msbuild/blob/main/documentation/wiki/Rebuilding-when-nothing-changed.md
Based on your observations, it sounds like you have projects expressing dependencies to other projects in a way that isn't obvious. It is possible for orphaned dependencies to remain in project files without being apparent in the UI. Have you looked through a misbehaving project file after opening it in a text editor? Checked solution build dependencies?
If you're not able to spot anything, try recreating one of your projects from scratch to see if the new project exhibits the same problem. If the clean project builds correctly, you'll know that you have unwanted dependencies expressed somewhere. As far as I know, these would have to be in the project file(s) or the solution file, unless you have makefiles or other unusual build steps.
Another problem that frequently happens is when some item in your solution has a modified stamp that is in the future. This can happen if you set your clock forward, and then set your clock to the correct time. I had this happen while installing Linux.
In this case you can recursively touch all the files using git bash (yes, in Windows):
find . -exec touch {} \;
I've finally found one more culprit that I had hard time finding by increasing the build log verbosity.
In some cases, MSBuild looks for vc120.pdb in the output folder, and if this file doesn't exist, it will rebuild the entire project. This occurs even if you have disabled debug symbol generation.
The workaround here is to enable debug symbols and let this file get generated, then disable the setting again without deleting the PDB file.
I had this same problem and it turned out to be related to a couple of project that had a copy local reference to a dll in their own output directory.
The key to finding this was having diagnostic output set for the build output, but also knowing what to look for in the log. Searching for: 'not up to date' was the key.
Here is an answer from VS2010 always rebuilds solution?
This issue is solved by changing the project files, cleaning solution,
deleting all bin folders by hand, restarting Visual studio and
rebuilding everything.
I had the same issues with you.
I found that it came from some deleted files.
When I had removed the files from my project, the issues was gone.
Regards.
For this category of build problems setting MSBuild output verbosity to 'diagnostic' is indeed a necessary first step. Most of the time the stated reason for the re-builds would be enough to act upon, BUT occasionally MSBuild would erroneously claim that some files are modified and need to be copied.
If that is the case, you'd need to either disable NTFS tunneling or duplicate your output folder to a new location. Here it is in more words.
I had the problem of Visual Studio rebuilding projects when upgrading from Visual Studio 2015 to 2017 and I add this answer for the benefit of those who might experience similar problems, as it does not seem to be documented anywhere.
In my case, the problem was that all projects in the solution had the same intermediate Output path (obj). The file GeneratedInternalTypeHelper.cs gets generated by all projects containing XAML. Up to Visual Studio 2015, the build process apparently did not check for the file date of this file and thus no problem with it occurred. With VS2017 the file date of this file is checked and because a later project in the build process will overwrite it (with the same content), the earlier project will re-build, re-triggering the later build, ad infinitum.
The solution in this case is to ensure that all projects have differing intermediate output directories, which will make the problem go away.
In my case (mixed C#, C++/CLI and native C++ solution) , some C++ projects were being re-linked even if nothing had changed. I spent ages trying to work out what was happening. In the end I worked out from the "Command Line" option that the PDB output path (option /Fd) could not handle the folder setting $(IntDir). I removed that - an empty value will do the default correctly - and my issue went away.
As others have noticed, a likely reason is that CopyToOutputDirectory is set to Always. This can be fixed simultaneously in all project files by applying the powershell script below:
$folder = "C:\My\Solution\Folder"
$csvFiles = Get-ChildItem $folder *.csproj -rec
foreach ($file in $csvFiles)
{
(Get-Content $file.PSPath -Encoding UTF8 -Raw) |
Foreach-Object { $_ -replace "<CopyToOutputDirectory>Always</CopyToOutputDirectory>", "<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>" } |
Set-Content $file.PSPath -Encoding UTF8 -NoNewline
}
Files that do not exist are a problem and obviously files producing no output as well. That can happen, wenn you have a resource file in a static library. (C++)