How to compile a .sln file that contains errors? - c#

I am making a modified version of Smart Steam Emu and it does contain some errors. I don't have the time and knowledge to fix some of these errors and there are tons. These errors (from what I know) also exist in the stable build.
I need to test something and I was wondering to compile the project if it contains errors. Thanks!
IDE: Visual Studio 2013
OS: Windows 10 Creators Update

As Ken said, you cannot compile the solution without resolving all the errors.
That said, there are a couple of ways if you just want to test a particular project, but the errors must be in the project that’s not referenced by the project you want to test.
First you need to Set the Project you want to test as Startup project
Method 1: Remove the erroneous project from solution. Run the project you want to test.
Method 2: Run the solution. Select “Yes” when VS prompts you with question that you want to continue to run with errors.
Hope this is helpful!

Related

Visual Studio doesn't put binaries of Unity project to output folder

I’m working on a solution containing default Unity project (Assembly-CSharp).
I added a test project to the solution with a reference to Assembly-CSharp. According to IntelliSense, the test project does see the types from Assembly-CSharp, however when I’m trying to build the solution, I’m getting the following error:
Metadata file 'MyProjectFolder\Temp\bin\Debug\Assembly-CSharp.dll' could not be found.
Thus, I'm not able to run unit tests on my Unity project.
Indeed, when I’m building the Unity projects, the .\Temp\bin\Debug folder remains empty even though the build is recognized as successful by VS.
The problem is caused by Disable the full build of projects setting which is new in Unity Tools extension. It prevents the binaries to be created, which speeds up situations when they're not actually being used, like when starting the debugger.
Turning this setting off in Visual Studio settings fixes the issue. Now all build products are placed in ./Temp/bin/Debug folder and I can run unit tests.
Feature request
I made a feature request to VS to make it possible to define this setting at solution level, so that you can have 1 solution for speed and 1 for unit testing. I hope it will get enough votes up: https://developercommunity.visualstudio.com/idea/798543/make-it-possible-to-manipulate-the-disable-the-ful.html
I have the same problem, and regenerate project files did the trick.
Edit => Preferences => External Tools => Regenerate Project Files

Error CS7038 (failed to emit module) only in Edit and Continue

I'm debugging a .NET 4.0 application in Visual Studio 2015. My application builds and runs fine, but when I try to edit and continue while running under the debugger, regardless of what changes I make or where I make them in my main project, I get a dialog that says:
Edits were made which cannot be compiled. Execution cannot continue
until the compiler errors are fixed.
As an example of the sort of change I'm talking about, I've tried adding this line in various methods:
Console.WriteLine("foo");
When I look in Visual Studio's Error List pane, I see only one error, CS7038, with the description "Failed to emit module '<my app name>'." No filename, line number, or character is given. There are no squiggly red underlines in my code. If I stop the running application, build with the changes, and run again, everything builds and runs just fine. So there seems to be some discrepancy between what the build-time compiler and the edit-and-continue compiler consider acceptable.
Does anyone know of a way to get more information about why the compile fails in Edit and Continue mode? I read something about attaching to and debugging the VBCSCompiler process, so I tried that, but even with all exception types set to break when thrown, the attached VS never broke.
I'm not sharing any code because this isn't a question about my code but rather about strategies for finding out what the Edit and Continue compiler thinks is wrong, and for all I know the source of the compiler error could be anywhere in my entire project.
Edit:
As mentioned in the comments, I was able to attach a debugger to Visual Studio and break when an exception was thrown upon clicking "Continue" after editing code. The exception was a System.NotSupportedException with the following message: "Changing the version of an assembly reference is not allowed during debugging". It listed the name of the assembly in question, which was a small VB.Net project used by my application, which is mostly in C#. I'm trying to build up an MCVE to submit to Microsoft, but currently I'm unable to reproduce the problem in a smaller solution with just one VB and one C# project.
Edit 2:
I've found a workaround and self-answered the question in case anyone else ever encounters this weird problem, but I'm reserving the "Answered" check mark for anyone who can explain what's going on (why the compiler thinks the version number of the referenced project has changed during the edit).
I found a workaround for the problem, but I don't fully understand what was going on. In the VB.NET project whose assembly version the Edit and Continue compiler said was changing, there was a file called "AssemblyInfo.vb". That file contained the following line:
<Assembly: AssemblyVersion("3.0.*")>
The assembly version can also be set in the Project Properties, via the "Assembly Information" button in the Application tab:
When I removed the AssemblyVersion line from AssemblyInfo.vb, my Edit and Continue problem went away. At first I thought this was because the fields in the Assembly Information window were saved to a different file from AssemblyInfo.vb and there was some conflict between the two, but now I see that the Assembly Information window is just a handy way to edit AssemblyInfo.vb: if I delete the line in AssemblyInfo.vb, it gets cleared in the Assembly Information window.
After some more experimentation, it appears that the asterisk in the version number is the culprit. If I fully specify the assembly version, my Edit and Continue problem goes away. And the referenced project has to be a VB.NET project. I tried the same setup with a C# project, and I could Edit and Continue just fine.
This appears to be very much an edge case, and I'll submit a bug report to Microsoft, but in the meantime I'd love to know what is actually going on with the compiler--why it's getting two different assembly versions of an assembly that really shouldn't need to be recompiled during the debugging.... If you have a good explanation for what's happening, please add it as an answer.
Edit: here's the bug report I filed.
This happened with me in a .net 4.8 app with Visual Studio 2019.
I have a mix vb and cs projects, here the problem appears when a vbproj references a csproj that uses the wildcast operator '*' to specify the version of the assembly.
As commented above by #Wai-Ha-Hee, the wildcast uses the current time, I belive when VS rebuild the application to apply the edits you have made, the version of the assembly changes causing the error.
In assemblyInfo file (of the project present in error) Change:
[assembly: AssemblyVersion("1.0.*")]
To:
[assembly: AssemblyVersion("1.0.0.0")]
It Solved for me.
An important thing to say is the use of wildcast '*' make the assembly non-deterministic, it means each build produces a different assembly. This has been considered bad practice because build the source code in the same conditions generates different assemblies.
In Visual Studio 2019:
New csproj/vbproj with non-sdk style projects file are generated with:
<Deterministic>true</Deterministic>
And new csproj/vbproj with Sdk style projects file omits this line but assumes deterministic as default too.
I recommend considerate other ways to version the assembly.
More about Deterministic:
http://blog.paranoidcoding.com/2016/04/05/deterministic-builds-in-roslyn.html
https://reproducible-builds.org/
One of my C# projects in a mixed solution was .NET Framework 2.0 (while others - both C# and VB.NET - were .NET Framework 4). After I changed it to .NET Framework 4 it began to work.

Solution fails to build w/ missing auto-generated .g.cs file for the first time, succeeds on second build

I'm building a WPF app w/ Visual Studio 2015 (Update 3), and—at least by now, I'm not sure for how long this has been the case—every time I make a change and compile, I'll get a failed build w/ the error
6>CSC : error CS2001: Source file 'C:[...]\Obj\Debug\AnyCPU\GeneratedInternalTypeHelper.g.cs' could not be found.`
If I just build a second time, though, it works just fine.
This smells to me like a dependency on another file that is generated afterwards or something like that, but I haven't been able to find out what it is, a google search didn't net anything either, and neither did a search through my project what this file is used for in the first place (the name suggests its purpose, but I don't know where exactly it is used).
It might also be that the (group-policy-mandated) Anti-Virus is holding an exclusive lock on the file or its dependency for a moment too long, and VS stumbles over that, I think I remember a problem like this at my last job, but I'm not sure that is the case (and I can't simply disable the scanner for a check, it's completely locked down and I don't want to violate company policy for trying to circumvent it).
Any ideas? It's not critical since it's easy to work around, but it's annoying and I don't really want to check in the project like this in the end.
I had the same issue and i found why it happened (in my case).
Every project of our solution has the same output folder.
The file GeneratedInternalTypeHelper.g.cs was generated at the same place for each project.
The build order/dependencies were computed and Visual Studio found that some project could be build in parallel.
In Tools > Options > Project & Solutions > Build and Run you can find the option "Maximum number of parallel project builds.
After changed from 8(in my case) to 1, no more files generated at the same time :)
It is a little slower to compile but really less annoying than compile multiple times... \o/
An alternative solution is to add project dependencies in the solution for the projects you don't want to build in parallel.
With this you can keep the parallel project build for the other projects.
I have just chased down the same error. In my case it was caused by Git checkout inserting a "%20" into the folder name of the solution where a space was expected. Replacing "%20" with space fixed all these missing *.g.cs errors. Thought worth mentioning here.

ReSharper cannot resolve symbol [duplicate]

This question already has answers here:
ReSharper "Cannot resolve symbol" even when project builds
(41 answers)
Closed last year.
I'm currently building an ASP.NET 5 (ASP.NET Core 1.0) MVC application. I'm using Visual Studio 2015 with ReSharper Ultimate 10.0.2.
I currently have a 2-tier layer solution which consists of a Www (web application) and a Services layer. The Www has a reference to the Services layer.
When ReSharper is suspended, the classes within the Www layer are able to invoke objects from the Services layer, as shown here:
However, when ReSharper is enabled, I get the following message: Cannot resolve symbol 'Services', as shown here:
What I've tried:
Clearing the caches from Tools -> Options -> ReSharper Ultimate -> Options -> Clear Caches
Remove the JetBrains folder from %APPDATA%
Restarting Visual Studio 2015
Reinstalling ReSharper
Suspending and resuming ReSharper
Adding and removing references
Rebuilding the solution
Any help is appreciated.
In Visual Studio 2017 I solved in this way:
Close the solution
Delete the ".vs" hidden folder
Reopen the solution and rebuild it
Looks like Jetbrains is aware of this: youtrack.jetbrains.com/issue/RSRP-408661
However, it gave me an idea. I set CopyLocal on the assembly to "true" and now my references resolve.
I had the same issue with v2017.1. Spent some time trying different solutions like clearing cache, suspending and resuming, but no success.
What helped me: I updated to v2017.3.1 (latest on time of writing). So if you facing a problem which you cant fix by simple suspending or clearing cache, consider updating to latest version, probably it was a small bug, and now it is fixed.
For me I got to reinstall MSBuild. Then it worked again.
It seems those "EMIT WARNING" defines come from "xkeycheck.h", a standard include file, which wants to check if a standard data type gets overwritten by some define. It seems that somehow ONLY resharper thinks that this is the case, while VisualStudio itself doesn't have any issues. The emitted warning never appears in a compile, only in resharper. I have this issue in exactly one file, and I couldn't yet find the real cause for it. Ayway, adding a "#define _ALLOW_KEYWORD_MACROS" in this file stopped resharper from running amok.

Getting mysterious build error after upgrading solution to Windows 8.1

I have used windows store apps 8.0 in my project and upgraded it to be 8.1. And also upgraded Visual Studio from 2012 to 2013.
First, I got an error that cannot use the Microsoft.VCLibs Version 11.0 and 12.0. So I removed the 11.0 version.
And then I got this errors:
I tried to find some information on the internet, but nothing.
Also when I double clicked on the error it doesn't bring me to the error's spot.
I have tried to do many things, and nothing helped, so I decided to write this post.
Can someone help me resolve this errors?
EDIT:
I am adding some more information, maybe this can lead to the problem:
Solved:
With the help of Hans Passant the errors have fixed. The problem was that I had this duplicate on my resource file:
I did it twice because one is for buttons (that has content), and one is for message dialogs on code behind.
In Visual Studio 2012 this code was working fine, but somehow, not in Visual Studio 2013.
I deleted the row of Cancel.Content and the errors disappeared and it works fine :)
Here is somebody else with the same problem.
I'll just copy Caplan's guidance. Look through the .resw file(s) in your project and look for a duplicated "Cancel" resource. I should note that intentionally forcing a duplicate resource produced another message when I built the program on VS2013:
1>MakePri : error 0x80073b0f: Processing Resources with error: Duplicate Entry.
1>MakePRI : error 0xdef00532: Conflicting values for resource 'Resources/String1'
Same message from either duplicating the resource in the same .resw file and by making a copy of the .resw file and adding it to the project. So Caplan's explanation isn't exactly a slam-dunk. I'd pay attention to other projects in your solution that might also have a resource named "Cancel". A likely scenario when your solution has a dependency on VCLibs, that sounds like you are mixing C# and C++/CX.
I came across this MSDN URL which seemed to be pretty helpful.
2 snippets in particular you could try:
You could actually have a duplicate resource entry in your project file.
Your obj files could have become corrupt, you need to clear out your obj files (although I haven't seen this problem for a while in my
team - it might be fixed in 2008).
If you are using a custom culture, perhaps with the .Net RegisterCulture method, ensure that the culture has been registered on
your computer. If you've reinstalled your OS and installed VS2008 and
you can't build due to this problem it could be because you need to
register your custom cultures before you build. This error seems to
be thrown when msbuild cannot find the culture.
Alternatively:
PS - There is also a Visual Studio 2012 Update 3 available that could possibly help?
Visual Studio 2012 Update 3
I hope this helps.
A similar error can also occur if you update a Nuget package in one project, but not in another dependent project also using the same Nuget package.
i.e. it can be a version mismatch error when referencing different versions of a dependency across two dependent projects.
I don't know if you have tried re-installing VS 2013, I was getting the same error but it was resolved when I re-installed.
In my case, after retargeting a working Win8 App for Win81 App, was UI string. Imho it is correct but soehow the VS2013 has some problems with it.
Locations SomeString
Locations.Text SomeStringForUI
Removing the one of them solved my problem.
Recently i got a similar build exception on my UWP Project
MakePri : error 0x80073b0f: Processing Resources failed with error: Doppelter Eintrag.
MakePRI : error 0xdef00532: Conflicting values for resource 'System.Design/ClassComments1'
I found a lot of information about the error but no solution. It looks like the error must be in the entry application project but it isn't.
In my case the VS integrated automaticly a reference to System.Activities because a made a mistake.
After i deleted the wrong reference, it works fine again.
Got this error in a UWP Xamarin.Forms project when a fellow developer referenced System.Web in a PCL that the Xamarin.Forms PCL references.
For more info:
Add System.Web Reference To A Windows 10 Universal App

Categories