I have a visual studio 2010 solution file containing a number of project files. If I clean the solution using devenv then the clean completes successfully, however, if I use MSBuild, two of the project files fail to clean due to a missing dependency, error MSB3395. If I run Clean a second time, immediately after the failure, the clean completes without errors.
Our build using MSBuild succeeds.
Task "UnregisterAssembly" (TaskId:204) ...
...
error MSB3395: Cannot unregister assembly
"C:\Build\Dir\MyFile.dll". Could not load file or
assembly 'MyOtherFile, Version=10.0.0.414,
Culture=neutral, PublicKeyToken=266e457ed35afd03' or one of its
dependencies. The system cannot find the file specified.
[C:\Build\Dir\ProjFolder\MyFileProj.vbproj]
Yes, this assembly is a COM interop assembly and so the build registers the assembly. If I delete the UnmanagedRegistration.cache files associated with the two problem areas then the clean finishes without problems. However, these files are not unregistered and registry fills up with old COM registrations. I am not certain of the impact on future builds either.
I have read the article for VS2008 projects here https://blogs.msdn.microsoft.com/visualstudio/2010/12/21/incorrect-solution-build-ordering-when-using-msbuild-exe/
However, I don't think this applies in this case because this build process has been cleaning and building properly for months.
I have also read: https://www.experts-exchange.com/questions/26259422/msbuild-can't-clean-project-with-C-COM-component-dependant-on-other-NET-library.html. I attempted to clean the two different projects before cleaning the solution affected by this, but this too failed. e.g.,
msbuild ".\ProjDir\MyProj.csproj" /t:clean /p:configuration=Release /fl /flp:logfile=".\..\LogFiles\msbuildClean.log";verbosity=diagnostic
I have tried reverting to a previous SVN revision before the problem began to show but I still get the same error. My build machines are on Virtual Machines, and I even tried reverting the build machine to a snapshot prior to the problem showing up, but still the error would show up.
I have been at this for two weeks now, and my only recourse is to use devenv to clean the solution, which is very slow. My only idea at this time is that when using msbuild that dependencies for COM interfaces are not handled correctly for a clean but I have no idea how to fix the problem.
I can reproduce the problem using the VS2010 CMD Prompt. Below is an example cmd line that I use
msbuild "A Solution.sln" /t:clean /p:Configuration=Release /fl /flp:logfile=".\..\LogFiles\msbuildClean.log";verbosity=diagnostic
msbuild "A Solution.sln" /t:build /p:Configuration=Release /fl /flp:logFile=".\..\LogFiles\msbuildBuild.log";verbosity=diagnostic
Within the vbproj files there are PropertyGroups with a Release configuration condition. All of these include <RegisterForComInterop>true</RegisterForComInterop>. If I set this value to false, then the error goes away because there isn't anything to unregister. However, I need the .tlb files in order to compile our vb6 project.
So, are there any problems for me to just set this to false and then use Regasm to register the assemblies post build, and unregister before a clean? Does anyone have any ideas why MSBuild would suddenly have problems with this process when for months the build has run successfully?
Thanks.
UPDATE
If I use msbuild to clean the first problem project, this clean works
successfully.
The second project however fails to clean properly
When cleaning the first project, ProjA, it also removes dependent
files from other projects, ProjB.
When I clean the second problem project, ProjC, it also has dependencies on ProjB.dll, and this file is missing.
QUESTION
- How do I keep MSBuild from removing files required by other projects?
In the end I have to go with stijn's answer.
I never did find the cause - something in the msbuild clean process seems to delete the files required to unregister an assembly.
I had tried to create a msbuild task to unregister the assemblies first, but that too failed.
In the end I coded a Powershell script that searched a path for *.unmanagedregistration.cache files. I then can determine the .dll file name from the unmanagedregistration.cache file and then once the code runs regasm /unregister, it will remove the file.
Just perform the clean as administrator. If using visual studio, open it as administrator and it should perform the clean action.
Have been trying to compile source from https://aspnetwebstack.codeplex.com/
Loaded Runtime.csproj,
added a project to be able to step through MVC source.
Disabled Delay Signing,
then built, and received.
Error 1 Cryptographic failure while signing assembly 'c:...\aspnetwebstack-master\src\System.Web.Mvc\obj\Debug\System.Web.Mvc.dll' -- 'Key file 'c:...\aspnetwebstack-master\src\System.Web.Mvc\35MSSharedLib1024.snk' is missing the private key needed for signing' C:\Files\Projects\aspnetwebstack-master\src\System.Web.Mvc\CSC System.Web.Mvc
(p.s. build.cmd built successfully but with skipstongnames enabled, but the project doesn't build for System.Web.Mvc and ofcourse for its dependencies).
Sorry for the open ended question but, what may I be doing wrong here
ok looks like Disabling Delay Signing was a mistake.
This link helped me through though
http://www.codedistillers.com/?p=53
Tried to reproduce the issue copying the source to another place, and retried the procedure.
Was thinking of recommending not to open Runtime.sln and built it from the IDE before running build.cmd from the Admin privileged command line, but found out that you should be able to build from the IDE without a problem and get your binaries in the aspnetwebstack-master/bin/Debug and can reference them in your project.
All seems to be working fine now. Added this for future reference and if someone else may stumble upon such a problem.
One more thing, if you build your source from build.cmd and your * Build failed * chances are there is a message asking you to postfix Skipskipstrongnames /e to the build command do so and it will succeed.
Some old walkthroughs misdirect by asking you to download Skipstrongnames.exe from the internet with failing links. Not to worry. Once you start the build process, either be it from the IDE or this build.cmd, the Nuget packages will be loaded and the Skipstrongnames.exe will be located in the aspnetwebstack-master/packages/Microsoft.Web.SkipStrongName.1.0.0/tools folder. version may vary overtime but just for reference thought to mention it here.
Hope this helps somebody
I am currently trialling Visual Studio Online with an On-Premises build server. I have managed to move a number of projects into VSOnline but for some reason have hit a brick wall with one.
The project appears to build correctly but when I get to the end of the build I get the following error:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets (4291): The command "copy *.dll ........\PROJECT NAME\bin\Debug /y" exited with code 1.
I have deleted the project and re-created to be sure there was nothing wrong with my initial setup. As far as I can tell I have followed exactly the same process to create this project as I have 2 others that have both worked perfectly.
When I take the MSBuild command that is actually executed and run that directly on the build server it works fine.
Is there any way to get more information about what is going wrong? Has anyone else come across something similar?
Switch your post build events to AfterBuild.
Always use properties instead of hard-coded names. E.g. use $(Configuration) instead of Debug or Release.
The Post Build events for several of the projects were causing the issue when building on TFS.
I added
IF "$(BuildingInsideVisualStudio)"=="true" ( copy command here )
to the Post Build Events so that they only run when building in Visual STudio and are ignored in TFS Build.
Why does Rebuild fail with no errors?
Since this morning, this error keeps showing up. I build the entire solution (25 C# managed projects) and a "Rebuild All failed" appears, but without any errors! (I have 13 warnings about COM not supporting Generics, but it's "normal" because one dll is exposed as COM.)
Not an answer per se - but you're better off looking at the output window and seeing what it says there.
Also, to help with that you might want to look at your MSBuild verbosity - as shown on this screenshot (last two options):
Beware - the highest level generates a MASSIVE amount of information.
Finally - running msbuild from the solution folder in a command prompt will really nail the issue - because error messages and warnings come up in red and yellow respectively.
I found my own solution and it is simple:
When this error occurs, save the project and close VS 2013. After that, re-open VS2013 and open the last project.
It works like a charm. But it is very annoying every time!
Many people reported this problem in VS2010, VS2012 and VS2013.
Could be a corrupt Solution User Options file.
Close the solution, delete its .suo (.v12.suo for VS2012+), reopen the solution, and Visual Studio will build a new one. You will lose the StartUp Project, breakpoints, bookmarks, which files are open, which projects/folders are expanded, etc. But that's all minor compared to the solution not building!
I had the same problem. I was trying to refrence a higher .net framework version(4.5.2) to lower .net framework version(4.5) which was causing build error. I made the version same in both projects and it worked.
Check the Output Window (View -> Output) as that will tell you what's going wrong. Sometimes a reference might be missing or there is an issue with the targeted version of .NET for one project in a solution.
Have you tried to clean the solution befor rebiuld it?
This is the list of checks & things I would do if I were you (try to build after each step):
Is error list activated? (Sometimes I forgot to activate and I can see only warnings & messages)
Check output window for error messages..
Clean solution.
Double check after clean that everything is deleted from debug folders.
Build it in release mode.
Build solution project to project until you isolate problematic project.
Remove COM and comment code to see if is this the source of problem.
Restart VS2010.
Restart windows.
Few moments ago I fix it with repair of .NET Framework installation (.NET Framework v4.0 Extended in my case).
I had the same issue in VS 2015. I tried the following with no success:
Close VS project and reopen
Close all open VS projects and reopen just the project that had the issue
Clean solution
Rebuild solution
Delete all files in bin\debug and bin\release
Lastly I tried Keith Robertson's answer, delete .suo (\Visual Studio 2015\Projects\[ProjectName]\.vs\[ProjectName]\v14\.suo). Although this didn't get me a good build, it did finally give me an error message stating that I had two entry points to my application. I went to application properties (Alt + Enter) and select a Startup object from the drop down.
This error seems a bit generic to me. I also went through this situation, but I managed to solve it differently than any of the ones mentioned here.
I have a project and several dependencies. And one of these dependencies has undergone a change.
When compiling the main project in debug mode, I verified that everything was ok.
However, switching to release mode and recompiling the problem occurred.Rebuild all failed and 0 Errors
By analyzing the debug output, I encountered an error:
Although the build dependencies are configured correctly. When compiling in release mode, the main project did not find the new method created in the secondary project.
So I had to recompile each secondary project one by one in release mode. After that, I recompiled the main project and everything worked.
Hope it helps someone!
I just had the same thing. For me, it helped to restart VS and run it as Administrator.
Select the appropriate target framework
- Right click on project
- Properties
- In application tab, Select the target framework
clean the solution
Try and build each project and see where the issue is.
Check each of the references (of each project) to make sure not have the yellow warning sign
Has the solution ever built?
I just had this happen to me, and realized that I left a '#error' line in my code and forgot about it. When I tried to build, the build failed but the #error line didn't show up in my errors.
Try searching all for '#error'
I fixed it on my new implementation of Visual Studio 2013 by going to the database project / Project Settings and noticing that the Target Platform was SQL Server 2014 instead of 2012 like it should be.
Once chance of getting this error is when we try re naming the service reference name, we give some other name in the service reference, but in the namespace some where it will be referring the old name, so if you delete and add a service reference then keep the same name, else we may face this error, but we can see the error in the Output window.
There are apparently many causes of this. I just found the cause of my issue: the .NET version of a new project I created was higher than the version of the top-level project. (4.5.2 vs 4.0)
I got a similar issue today, and fixed it with repair.
Start
Run…
Appwiz.cpl
(Find your installed Visual Studio version)
Right click
Change
Repair
In my case it was the wrong date and time of computer.
I was getting no feedback/messages/errors. Just that all projects failed to build.
I closed and tried again--I noticed an error saying "you are not authorized to access..."
I clicked on my account, re-entered my credentials, and rebuilt the solution.
Voila! I got what I am used to seeing when I build a solution -- plenty of errors in all their glory.
Hope this helps someone.
Here's yet another reason which may sound familiar to some. I had integrated some code into my solution that wrapped a DLL. The C# code file that came with it offered a nice managed API and handled the low-level LoadLibrary stuff to access the DLL. Both had the same base name, so I had SomeName.cs and SomeName.dll. I could just drop it into any project and it would work.
This wasn't so nice after a while as I started using it in different projects. I got copies of both the DLL and the wrapper code in multiple projects. So I figured it would be better to drop the wrapper code and the DLL into a new class library project and then reference that new project from other projects.
After I had done that, I started to get this issue. The build went well up until the very last stage and then failed without error. Output showed nothing but successes.
The problem was the name of the wrapping class library project. I used the same base name (SomeName) for this. By default the assembly name would be SomeName.dll and I already had one such file (the DLL to be wrapped), thus I had a conflict with output files.
After renaming the wrapping project and its output assembly to SomeNameWrapper, the problem went away.
This may not be your exact cause but it seems likely you have some name clash or deployment issue as well. And it is not surprising the compiler won't give you an error because there is no problem in the compilation phase, the trouble starts with deployment and apparently this does not come out in an obvious way.
I had the same problem the original poster was displaying with 0 errors and Rebuild all succeeded. The Output tab showed a message that a referenced dll was built with a higher version of the .NET Framework.
Changing the .NET framework to match resolved the issue I was having with 0 Errors and Rebuild All succeeded.
The solution:
Because Prerequisites not set for debug set only for release
01-Change solution configuration ( in main screen )
set (debug to release)
set solution platform to (Any CPU)
02-Set Prerequisites for debug ( If you want to continue in debug mode )
03-set target platform version for all Projects
Some of the files included in your solution are not in the correct directories, or you have changed the name of one or more directories in your application. In the solution explorer under Setup review the list of all files and remove those that are not properly listed in the SourcePath Property.
One of my dependency in View file caused this. Check your view files for any dependencies which is not injected yet.
I have a Visual Studio solution with four C# projects in it. I want to step into the code of a supporting project in the solution from my main project, but when I use the "Step into" key, it just skips over the call into that other project. I've set breakpoints in the supporting project, and they're ignored, and I can't for the life of me get it to step into any references to that project.
Everything is set to compile as "Debug", and I've seen Visual Studio warn me that my breakpoints won't be hit before - it doesn't do that in this case. It's as though it looks as though my code will debug, but then at run-time, there's a setting somewhere that tells Visual Studio not to step through the code in that project. All the other projects in my solutions debug without problems.
What box have I checked to cause this behavior?
UPDATE FOR CLARITY: The "Just my code" option is currently disabled. Also, since the code belongs to a project in my same solution, I don't think the "Just my code" option applies here. I thought it only applied to pre-compiled code that I didn't have the source for, but since I have the source in my project, I don't think this option has any effect.
Not sure if this is it, but "Tools>Options>Debugging>General:Enable Just My Code" is a possibility. (I prefer to always leave this unchecked.)
It turns out that the assembly needed to be copied into the GAC before it could be debugged. Under the debugging option "Just my code", there's an option to suppress an error if you don't have any user code, and it was suppressing the following error:
The Following mobile was built either
with optimizations enabled or without
debug information. (Module name and
path) To debug this module, change its
build configuration to Debug mode.
Since I was building it in Debug configuration, I searched on that error message and got this:
http://claytonj.wordpress.com/2008/01/04/the-following-module-was-built-either-with-optimizations-enabled-or-without-debug-information/
Problem solved. I don't know why it needs to be in the GAC in order for me to step into the project, but it does. I don't ask why, I just ask how, and then I do it...
One thing to check for is that your supporting project assembly has not been installed in the GAC. Open a command prompt and run the following to make sure...
gacutil /l assemblyName
You need to ensure the supporting projects have pdb files or else Visual Studio will not have the necessary information to step through the code.
If you have the source code for the dll's into which you are trying to step into, do the following:
Click on the project in which these dll's are added as reference and remove them.
Add the Project(s) corresponding to the dll(s) to the solution
Right click on the project -> Add Reference -> Choose the newly added Project(s).
Now set the break point and debug the code.. You will be able to step into the code.
The reason for the issue is because you program is still referencing the old dll (without the source code) as it has been added to your project as a reference. Once you remove that dll and add the Project (Source code of the dll) of the dll, Visual studio will be able to step into your code.
A couple of possibilities:
There is a check box to step into "just my code". Its intent is to make it so you can't step into Microsoft's Framework code (unless you choose to by unchecking the box).
You might try recompiling the supporting code to make sure the code you're debugging exactly matches the code file you're looking at. VS does care about this and will disable a breakpoint if you put it in the code file whose version doesn't match. Also, make sure the PDB file is in the same directory as the DLL.
In Visual Studio 2013 one way to cause this behaviour is to set build configuration to Release.
Put it back to Debug and see if that helps.