How can I fix "build failed, do you want to continue"? In Visual Studio Code - visual-studio-code

I got an error when trying to debug Java code in Visual Studio Code.
The error is below
build failed, do you want to continue?
I have tried clearing the workspace, but it doesn't work. How can I fix this issue?

The problem was solved.
I resolved this issue by clearing the workspace cache in Visual Studio Code. Here is a link to the relevant page: Visual Studio Code Clean Workspace Directory. I had renamed a number of folders, class names and packages.
Apparently the Red Hat Developer plugin managed to get out of sync. The .classpath file was out of sync with the POM file. Wiping out the workspace cache caused the plugin to recreate project data from the Maven specification. The problem was solved. I am not sure, but if anyone from the Red Hat project reads this, it looks to me like a bug, or deficiency. In any event it can be worked around.
Original answer:
I think Liu Bei was not clear enough. I am experiencing the same issue. I have a project that builds perfectly in Maven and when I launch the debugger in Visual Studio Code this notification appears in the lower right-hand corner of the Visual Studio Code window.
Obviously the "Debugger for Java" extension thinks there is a build problem. However there are no errors reported in the PROBLEMS, OUTPUT, DEBUG CONSOLE or TERMINAL tabs.
The project builds, and packages in Maven just fine and it can be debugged in attach mode which is tedious at best.
There is something going on in Visual Studio Code that's not being reported anywhere that I can find. I suspect the RedHat Visual Studio Code plugin for Java is in the mix, but I need help figuring out how to work around the issue.
I have to say that we are spending way too much time resolving issues with tools and dependencies and not enough time on the app. The project we are working on is intended for open source distribution. The Spring Framework seems ideal for our purposes, but the tooling, not so much. We are not very far into the project and I am already receiving pressure to switch to ASP.NET Core.
I really need a little help...

This didn't work for me, but I found out what did.
First of all, looking at the Java Dependencies plugin gave me a hint that something was out of sync. The name of my application (artifact) did not match the name in the Java Dependencies tree view.
This was fixed by clearing the Visual Studio Code workspaceStorage folder completely!
This folder was in my case located in (Windows 10):
C:\Users\<myuser>\AppData\Roaming\Code\User\workspaceStorage
If you can't find it at this location, simply search for the folder workspaceStorage.
Next press Ctrl + Shift + P (in my case) to open the Visual Studio Code action prompt. Then choose the command:
Java: Open Java Language Server Log File
This will open a log file which is normally not displayed when building your Java code, and will tell you exactly what went wrong with the build.
In my case it was a conflict as I had two AppConfig.java files, one in main and one in test. Maven handles this fine, but apparently the Visual Studio Code Java builder does not.
Obviously these are bugs in the plugins which I will report to the GitHub contributors, but for now we will have to live with a little manual work.
Still I hope this helps all of you frustrated Visual Studio Code Java developers out there.

It worked for me to change the user setting in file setting.json to "java.debug.settings.forceBuildBeforeLaunch": false in Visual Studio Code, which will disable the check before run/debug.

Build failed error in Visual Studio Code
This error occurs because in your workspace folder the other source code has some errors in it.
So create a new folder and make it as a workspace folder and then write your codes in that folder and run it.
I had that error also and it worked for me, so check for yours.

Using OS X, I managed to overcome this problem. You can either access it from your Terminal or simply use a
shortcut (Command + Shift + C).
Select Base System and Library. Look for the Java folder and click on the Java Virtual Machines folder.
Check if is there the actual version of JDK (most up to date). I've noticed that I had two JDK folders one probably inherited from a previously installation and the most up-to-date Java 15. I dragged 'jdk-14' to the waste bin. Enter password, close finder and restart Visual Studio Code.
It works fine now!

For me, the problem was that I created a folder within a folder for arranging my Java program files with the reference to data structures. In the log file, it was showing that the .java file in the inner folder was not on its project's build path.
Just after deleting that folder and completely deleting all the files in the workspace folder manually in the location C:\Users<myuser>\AppData\Roaming\Code\User\workspaceStorage, this problem was solved!

I fixed this problem by doing the following steps:
Step 1: Opening Visual Studio Code settings (bottom left) https://i.stack.imgur.com/xPlkj.png
Step 2: Searching "Java debug" and selecting Java Debugger under Extensions https://i.stack.imgur.com/797M3.png
Step 3: Find Force Build Before Launch and uncheck it https://i.stack.imgur.com/igtRa.png
And you're done!

First of all, check carefully the errors on Visual Studio Code log and try to not get biased by the community common errors. To do this, press Ctrl + Shift + P to open the Visual Studio Code action prompt. Then choose the command:
Java: Open Java Language Server Log File
By doing this you can find the exact exception that is happening. In my case, I had two exceptions:
java.lang.NoClassDefFoundError: javax/annotation/processing/AbstractProcessor
And
java.lang.NoClassDefFoundError: com.demo.myapplication
So, I was biased to think that error was related to the Java version or stuff like that, but it was related to a Lombok extension installed in Visual Studio Code.
In the end, I found this thread and tested this solution and it worked like a charm.
Here is the solution explained by him:
Finally I got it working. The issue is with the additional argument -Xbootclasspath added by the Lombok extension to the java.jdt.ls.vmargs. I figured it out by integrating the Lombok with eclipse and opened the eclipse.ini file for the changes.
I uninstalled the vscode-lombok extension;
I downloaded the lombok.jar (version 1.18.6) file from https://projectlombok.org/download;
In Visual Studio Code, in settings.json, for java.jdt.ls.vmargs key, I added the argument
-javaagent:"PATH_TO_DOWNLOADED_LOMBOK_JAR_FILE"
A last necessary step (missed by the GitHub guy) is to reinstall the Lombok extension.

I had the same problem.
I just downloaded this provided for Visual Studio Code,
Extension Pack for Java.
Click on the link, download and open it. It will automatically configure Visual Studio Code for Java.

Related

Import Eclipse C++ Workspace Into Visual Studio Code for Linux

I have a workspace in Eclipse on Linux Mint. This project builds for and ARM platform device running Debian linux.
I am not an expert on this. We have a guru who set it all up for us. I am not sure which method the project uses to build the apps, but I do know all I have to do it right click the project in Eclipse and select build on any of the apps and they build.
I would like to use VS Code to develop this app. Is there any way to import the whole workspace into VS Code and have it actually build and debug on the target device?
If so can someone please give me the steps?
I just clicked menu item File->Open Folder...
Then navigate to the parent folder of your workspace, which is actually your Eclipse workspace folder. Highlight it, then click the Select Folder button. Then it just loaded all my Source files in. I can't tell you how to convert to building your code, as I only did this to search files and hopefully find variable's definitions. And this worked! I didn't even need to do a full scan of my source files or anything (or maybe it did this automatically at some point). I just went to the definition-unknown variable's location I know about, highlighted it, and right-clicked and selected Go to definition, and it went and opened the file with its definition.

Visual studio Intellisense color-coding not working for unity script editing [duplicate]

When I want to edit C# Unity scripts, they open in Visual Studio. It is supposed to provide auto complete for all Unity related code, but it doesn't work.
Here you can see the missing functionality:
As seen, the transform object does not open the autocomplete menu.
Unity version: 5.5.2f1
Visual studio 2015
Visual Studio Tools for Unity is installed
There is no auto-completion because the script says "Miscellaneous Files" instead of the of the name of the Project. Take a look at the image below that came from the video in your question:
The "Miscellaneous Files" message can happen for many reasons:
It can happen when you open your Unity C# file from another folder instead of opening it from Unity Editor.
This can also happen because Unity crashed while Visual Studio is still open therefore corrupting some files.
It can happen because Unity was closed then re-opened but is no longer connected to Visual Studio. When Visual Studio is opened you get "Miscellaneous Files" and no auto-completion.
This can happen when Visual Studio Tools for unity is not installed.
When you create a script from Unity then quickly open it before Unity finish processing it or before the round icon animation stuff finish animating.
Most of the times, restarting Unity and Visual Studio should fix this.
I can't tell which one is causing the problem but I will cover the most likely solution to fix this.
Fix Part 1:
Download and Install Visual Studio Tools for unity from this link. Do this while Unity and Visual Studio are both closed.
From Unity Editor, go to Edit → Preferences... → External Tools. On the External Script Editor drop down menu, change that to Visual Studio 2015.
Fix Part 2:
If newly created C# files are coming up as Miscellaneous then follow the instruction below:
From Visual Studio, go to Tools → Options... → Tools for Unity → Miscellaneous. Under Show connectivity icon, set it to true then restart Visual Studio.
When you re-start, connection icon should now be available in Visual Studio. Click it then choose the Unity instance to connect to. The red 'x' icon should now turn into a brown checkmark icon. Now, when you create a new C# file in Unity, it should open without saying Miscellaneous.
Fix Part 3:
Still not fixed?
Re-import project then open C# Project.
Close Visual Studio.
From Unity, re-import project by going to Assets → Reimport All.
Now, open the project in Visual Studio by going to Assets → Open C# Project. This will reload the project and fix possible solution file problems.
Fix Part 4:
Still not fixed?
Fix each C# file individually.
Click on Show All Files icon.
Select the script that doesn't do auto-complete then right-click and select Include In Project.
Fix Part 5:
Not fixed yet?
Credit goes to chrisvarnz for this particular solution which seems to have worked for multiple people.
Close Visual Studio
Go your project directory and delete all the generated Visual Studio files.
These are the files extensions to delete:
.csproj
.user
.sln
Example:
Let's say that the name of your Project is called Target_Shoot, these are what the files to delete should look like:
Target_Shoot.csproj
Target_Shoot.Editor.csproj
Target_Shoot.Editor.csproj.user
Target_Shoot.Player.csproj
Target_Shoot.Player.csproj.user
Target_Shoot.sln
Do not delete anything else.
Double click on the script again from Unity which should generate new Visual Studio file then open Visual Studio. This may solve your problem.
Fix Part 6:
If not working, check if you are having this error:
The "GetReferenceNearestTargetFrameworkTask" task was not found
Install Nuget PackageManager from here.
Restart Visual Studio.
See this answer for more information.
Fix Part 7
Make sure all of the projects are loaded.
In Solution Explorer it should tell you # of # projects.
If all of the projects are not showing, right click on "Solution (# of # projects)" and click Load Projects.
Try this,
In Unity Editor Go to Menu, Click on Edit -> Preferences -> External Tools -> External Script Editor. Set it to Visual Studio (your installed version of VS).
Now in Menubar go to Edit -> Project Settings -> Player Settings -> Other Settings -> Under Configuration -> Check API Compatibility Level -> Change it to your installed .Net version. In my case I set it to .Net 4.x
Now if Visual Studio is running already go to Visual Studio, it will ask to reload project. Reload the project. Check if it works, if not close Visual Studio. Now Open cs file from Unity Editor, and now it should work.
I found another way to fix this issue in a more convenient manner:
Select the broken file in Solution Explorer.
Open its Properties.
Switch field "Build Action" from "Compile" to "None".
Then switch it back to "Compile".
This will kill the synchronization between Unity and Visual Studio somehow.
The next time Visual Studio will reload the project, it will prompt a warning.
Just click on "Discard".
If you have done all of the above and still isn't working , just try this:
Note: you should have updated VS.
Goto Unity > edit> preference >External tools> external script editor.
Somehow for me I had not selected "visual studio" for external script editor and it was not working. As soon as i selected this and doubled clicked on c# file from unity it started working.
I hope it helps you too.
Unload and reload the project, in Visual Studio:
right click your project in Solution Explorer
select Unload Project
select Reload Project
Fixed!
I found this solution to work the best (easiest), having run into the problem multiple times.
Source: https://alexdunn.org/2017/04/26/xamarin-tips-fixing-the-highlighting-drop-in-your-xamarin-android-projects/
This page helped me fix the issue.
Fix for Unity disconnected from Visual Studio
In the Unity Editor, select the Edit > Preferences menu.
Select the External Tools tab on the left.
For External Script Editor, Choose the Visual Studio version you have.
Click regenerate Files
You Done
Select project in Visual Studio
Click "Refresh" button
I hit the same issues today using Visual Studio 2017 15.4.5 with Unity 2017.
I was able to fix the issue by right clicking on the project in Visual Studio and changing the target framework from 3.5 to 4.5.
Hope this helps anyone else in a similar scenario.
Two Alternative Options:
Fix 1
#singleton pointed me in this direction. Instead of changing the target in Visual Studio you should change it in Unity since the project is auto-generated.
First delete the auto generated Visual Studio files:
.csproj
.user
.sln
Then from within Unity go to PlayerSettings and under 'Other Settings' change the 'Scripting Runtime Version' from Stable 3.5 to Experimental 4.6.
However, that didn't fix it for me.
Fix 2
I noticed all of the references to Unity related code was marked with a yellow warning. Check your error logs and see if this is the case. In particular see if you get the following error: getreferenceNearestTargetframeworkTask
If so try:
Start Visual Studio Installer again.
On the Build Tools 2017, click Modify,
Ensure that "Nuget targets and build tasks" are ticked. This should become ticked if you click on Universal Windows Platform development.
Update 2020 with Visual Studio Community 2019 and Unity 2019.3:
Open Visual Studio Installer as Administrator, select to modify your current installation and add "Game development for Unity"
If you add a new c# script in Unity now, and open it (automatically) with Visual Studio, it is not described as "Miscellaneous" at the top of the window but with "Assembly-CSharp", and the autocomplete works.
i found my solution by creating the .cs file from visual studio itself instead of unity editor
right click on project folder in solution explorer
add > new item
type "unity" on the search field on the top right
select "CSharp MonoBehaviour"
name your script on the bottom and click Add
In my case, correct .net version was not installed on my PC. I install the .net 3.5 on my pc and that worked for me.
For Windows or macOS:
Download/Install the Visual Studio IDE (with Unity Tools)
When installing, make sure you include installation of
Game development with Unity
Then using Unity (you can double click one of your C# files), open a new C# project and the Visual Studio IDE should open with your new project structure.
From there, you should be able to see what you are looking for.
For example:
For Linux (suggestion):
Try Monodevelop - Additional Information, it provides code completion/hints.
My autocomplete also didn't work because Visual Studio Tools for Unity wasn't installed. So, after you install that, delete the auto generated Visual Studio files. Others said that you open file again and the problem is solved but it's not.
The trick is: instead of normally double-clicking the file, you need to open the C# file from Unity by right click and then "Open C# Project".
The issue I faced was that the C# Project was targeting a different .NET Framework (4.7.2), whereas the Unity project had a different target (.NET 3.5).
I fixed this by changing the target in Unity as-
File -> Build Settings -> Player Settings -> Other Settings -> API
Compatibility Level : Set it to the .NET version you already have
installed (Check your .NET Version here). In my case, it was 4.x
After this, Visual Studio worked perfectly and autocorrect was fixed too.
Try pressing Ctrl + Alt + Space (which toggles between suggestion and standard completion modes)
For some odd reason, the "Game development with Unity" tool can become disabled in Visual Studio.
To fix this..
Open Visual Studio
Go to Extensions → "Manage Extensions" → Installed
Find "Visual Studio 2019 Tools for Unity"
If it is disabled, enable it
Restart VS
Credit to Yuli Levtov's answer on another Thread
The following works for me.
Go to Edit->Preferences->External Tools->External Script Editor Select Scripting Editor
I solved to install the same version of .NET on WIN that was configured in my Unity project. (Player Settings)
Go to Options on the Tools menu and then select Documents in the Environment node. (If Documents does not appear in the list, select Show all settings in the Options dialog box.)
Put a tick on "Miscellaneous files in Solution Explorer" and Click OK. (This option displays the "Miscellaneous Files" node in Solution Explorer. Miscellaneous files are files that are not associated with a project or solution but can appear in Solution Explorer for your convenience if you tick this option.)
Locate your file in the Solution Explorer under "Miscellaneous Files". Then drag and drop your file to where it should belong and voila! This will copy the file to where you drop it. You may now safely delete the older file under Miscellaneous Files folder if you wish to do so
Credits: https://stackoverflow.com/a/47662523/10471480
In case Scripts folder is not visible:
Click on "Show all files" in Solution Explorer
Locate the Scripts folder.
Right Click on Scripts and select "Include in Project"
Keep in mind that if you are using the ReSharper tool, it will override the IntelliSense and show it's own. To change that, on VS, go to Extensions -> ReSharper -> Options -> IntelliSense -> General then choose Visual Studio and not ReSharper.
Before restarting and/or re-installing VS, First try opening any other of your projects to see if Intellisence works, if it does, then issue probably lies with your current project. First, most probable victim would be the NUGET packages with pending updates. To Fix this,
Right click on references
Proceed to Manage NUGET Packages Under NUGET Packages
proceed to updates Install Updates and recheck Intellisence
I tried all of these but ended up finding out that I needed to right-click the solution in Solution Explorer and add existing items and find the C# assembly file in Window's Explorer. There seem to be a bazillion different problems that give you this error, this is likely the most simple solution. If you double click on your script from unity, it does not seem to drag the assembly along.
Another possible fix:
In the project window, click on the Assets folder
Right click, and Create -> C# Script
Double click that, and wait.
For some reason, this work.
None of the above solutions worked for me. However I opened the ProjectName.CSPROJ file and manually added the new file and it worked like charm
What worked me is that I copied all the code inside the broken class and removed that file.
Then, I opened an empty file with the same name and pasted back.
Result: beautiful syntax highlights came back!
"Preferences" -> "External tools" -> set you exteranl tool
Thats one fix. Also for VS you can use ReSharper by JetBrains, but I recommend use Rider. That one is also free for students.
It provides less performance than visual studio, but more than VS+Resharper definitely.
Have a good day, mate)
Try with combination: Ctrl + Alt + Space
one of the above methods are worked for me and I just found a solution to this problem,
1. First, go to the project directory and delete .sln file
2. Second, go to unity and double click your script. Then Visual Studio will be open with an error,
Then click ok and close Visual Studio editor.
Finally, turn off your Windows Defender and then go to your project directory and there will be .csproj file. Just double click and open this from your Visual Studio editor and open the scripts folder inside the assets folder and open the scripts and autocompletion will be working perfectly fine.
These actions solved the problem for my projects in Visual Studio 2022
FIX 1
Solution
Assembly-CSharp (right-click)
Load Entire Dependency Tree
FIX 2
Solution
Assembly-CSharp
References
Double click on any lib to force loading

PhantomJS Project in Eclipse (with Nodeclipse): NullPointerException when trying to run js file that is present in a folder

I wish to create a PhantomJS Project in Eclipse for which I have installed the Nodeclipse PhantomJS 0.12+ plugin. I am selecting the below project type:
The script runs fine when I arrange the project in the following way (without any folders).
But, when I place the same .js file in a folder and try to run it, I end up getting a NullPointerException (see screenshot below).
The error that I'm getting is below:
An internal error occurred during: "Launching PhantomJSTest-Test1.js".
java.lang.NullPointerException
Screenshot:
What I have tried:
I found a similar question on Stackoverflow with the same error but for Android. I have tried cleaning, building the project. But, the error occurs only when I create a folder structure in my project. If I don't, then the script runs fine. In short, I am not able to organize the project.
Questions:
I'd like to know what type of folder structure is valid / will work for a PhantomJS project?
Why is the NullPointerException occuring?
Are there any other easy alternatives to setting up a PhantomJS project?
Any help / guidance regarding the folder structure is highly appreciated.
First get the latest version, that is 0.17, see news/history at http://www.nodeclipse.org/
If the problem is still on, raise issue on https://github.com/nodeclipse/nodeclipse-1/ (and reference this question)
To the questions:
PhantomJS launcher is rather simple https://github.com/Nodeclipse/nodeclipse-1/tree/master/org.nodeclipse.phantomjs, and it should work for any .js file (in any project type). PhantomJS project type is for beauty sake only, as it is just JavaScript project.
NullPointerException should occur never, so it may be bug.
You can create general project as well. But with JSDT and Tern you would get some Content Assist. For new module support with Tern raise issue at https://github.com/angelozerr/tern.java/
I switched to using Enide Studio and that solved the folder structure issue for me.
Here's what is needed to setup PhantomJS Project:
PhantomJS
Enide Studio
Steps:
Download PhantomJS
Download and launch Enide Studio
Goto Window->Preferences->Nodeclipse->PhantomJS and set PhantomJS Path to 'phantomjs.exe' file path
Create a PhantomJS Project (like any normal project)

Eclipse does not seem to recognize Native Android code

I am trying to learn about native Android, using NDK.
I find some sample projects in NDK folder and on the Internet. After much configuration, they are runnable.
But, my problem is: when I open a .c or .h file in JNI folder with Eclipse (just want to see what it is), Eclipse shows many error in this file. For example, it don't know what is JNIEnv, jobject, jstring.
I haven't made any change in the project, just opening it. Errors mean I can't rerun it again except if I delete it from the workspace then reimport it.
Eclipse does not work well with C/C++ files. At least, for me it did not.
After some search, I have managed to configure Code::Blocks to support NDK, please see this answer to the question:
Need a simple Linux C++ IDE (Android NDK) .

the Eclipse executable launcher was unable to locate its companion shared library error message

I decided to turn over a new leaf and start learning Java, but after downloading eclipse I cannot seem to make it run. I originally got an error saying it couldn't find my VM so I changed the path in the eclipse.ini to where "Java Mission Control" is installed, and now it's giving me this error when I try to run the application. I have looked at many other posts where people get the same error message but they all have to do with wrongly unzipped files and I am quite sure I unzipped it properly. I have also tried different mirrors and redownloaded eclipse 5 or 6 times as well as reinstalled JDK with no avail. I have used WinZip, Windows file explorer, and Jzip all to unzip the file with the same message.
Windows 7 64bit
8gb ram,i7, 660ti graphics
If you copy and paste all of the contents into a folder on your desktop, you can then use the eclipse.exe file just fine.
I had the same problem with Eclipse. I even had a very similar problem when trying to install the Android Studio (I wanted to compare Eclipse and Android Studio). The difference with Android Studio was the error message (forgot exactly, but was saying that I was missing a .dll file that was important).
The simple thing that solved the problem:
I moved the original .zip file out of the folder where the unzipped files were created (I moved to the desktop). You can even delete it definitely because once unzipped we don't need it anymore. Then, the Eclipse.exe run smoothly (even before running it I noticed its icon changed after I eliminated the .zip). Then I went and did the same for Android Studio, run the corresponding .exe file, and tara-raaaan: run too!!!
Easy... but not obvious at all, I know. Hope this helps!
PD: Before this problem I had another one. It was related with Java (JDK); I had to add the path where it was installed and that solved the problem.