namespace can't be found by omnisharp even though unity builds - c#

I am using vscode to edit unity scripts, I've added Mirror for needs, which extends its own namespace, but the problem is that omnisharp can't find it's namespace. All Mirror's files are under Assets/Thirdparty/Mirror
Everything works in terms of compiling and the result, but I have no idea how omnisharp works and how to configure it.
Below you can see waving lines at everything that is extended by the namespace.

Sometimes I have that too, especially when I just updated VS Code or added a package in Unity. And sometimes this helps:
Press the Regenerate project files button in Project Preferences.

For me installing .NET Framework 4.7.1 Developer Pack fixed the problem.

Related

Visual Studio Intellisense Can Find References But Build Fails Due To Missing References

I'm currently running into an issue (on Visual Studio 2022) where the test project within my solution is referencing a few other projects in my solution; however, trying to build the test project results in errors for these project references. Even more interesting is that this test project used to be working fine.
So far I've:
Double checked the pathing of the project dll's being referenced
Removed and re-added the project references.
Editing the file, Intellisense is able to find the references, but when building the console output shows errors.
Cleaned the solution
Seen recommendations online of clearing the Temp folder and AppData\Local\Microsoft\VisualStudio\17.x\ComponentModelCache for my user account and have done so
None of this has helped. Any guidance on what to research or things to try/insight to the problem would be much appreciated!
Thank you
-Austin
EDIT 1 (7/5/2022)
Error List Image
The error seem to resolve themselves when I click on them from the Error Lists (after viewing the place in the file where the reference error is occurring, the error disappears after a few seconds, removing it from the Error List and also the removing the red squiggle underline). However, the error does not actually resolve as there are still the same reference errors when trying to Build the test project.
For example, STEP.Entities is a project in the solution that is referenced by the test project. However, the test project can't find the referred Entities project.
I realized the issue was caused by packages used in the other projects of the solution were targeting different .NET versions than the same packages within the Test project.
(Firstly, to determine this I went to Tools > Projects and Solutions > Build and Run > select MSBuild Project Build Verbosity as Diagnostic. (I believe this generates more a detailed report of the status to the Output Console when building projects)).
Specifically, a lot of these packages in my test project were targeting .NET v 4.8 as opposed to v4.7.2 being targeted by packages in the other projects, and the Test project itself and other projects targeting v4.7.2. I updated my Test project to target v4.8 and everything works/references can be found.
I've had this problem recently with a project from GitHub, my best sugestion is to try checking the version you are using and maybe select an older version of the said references.
It took me a while to get it done but it worked.
I think I worked around this with following global.json in the root of my drive:
C:\global.json
{
"sdk": {
"version": "6.0.300",
"rollForward": "latestFeature",
"allowPrerelease": false
}
}
Or there might be a global.json in your solution somewhere, with a .NET SDK version that doesn't exist...
To list all installed .NET sdks on your computer, run
dotnet --list-sdks
and pick the correct version.

New to Visual Studio, program won't build

I am relatively new to Visual Studio, C#, and using Github. I am trying to get the example for AncestralTrees working (Found here: https://github.com/fire-eggs/Ancestral-Tree). I cloned the repo and try to build, but I get a set of errors that do not make sense.
First is that AppSettings.cs and MruStripMenu.cs could not be found. Are these default config files I have to provide, or am I missing something?
And second is that .NET framework v4.5 wasn't found. For this I am a bit confused, because I thought it was backwards compatible, and I have v6.0.301 installed. To try and fix this error, I went to the website provided and downloaded it, but it wouldn't install as I already have a newer version. Again, am I missing something?
Any help would be greatly appreciated!
For the compatibility issue, .Net Core (6.0) and .Net Framework (4.5) are different animals, with .Net Core as more of a successor to Framework. They are very similar, but there are some breaking changes between Framework and Core, and if a project was intended for .Net Framework 4.5 you will want to have it installed on your system and set as the build target for the project in Visual Studio. You could probably also build for 4.7 or 4.8.
For the files, if they are part of the repo I would expect them to be there. I'd check your file system and see if the files are there, and then check the repo on github and see if they are included in the repo. If not, you may need an additional repo or you may need to manually add a NuGet package.
I did notice this at the bottom of the github page:
This program is both a demo of my GEDCOM library: YAGP, and a hopefully useful program in itself.
Where the "YAGP" text is a dead link. So I would expect to also need this project, which either no longer exists or is not public. This is probably the correct address:
https://github.com/fire-eggs/YAGP
(I submitted a change with the fixed link.)

I try to set in Unity ะก# Project framework 4.6.1 but it return to 4.7.1 after save the project

I use Unity 2019.4.2f1 and Rider 2019.2.3.
I tried to use a library NPOI, but it need framework version 4.6.1.
Ok, I had set the version 4.6.1 in the solutions Assembly-CSharp and Assembly-CSharp-Editor.
All right, it works. But next step I had save the project and get errors because... the framework in the solution becomes again 4.7.1.
Ok. I tried do it with Visual Studio 2019 and I got same result.
Ok. I tried to write set framework's version in the files Assembly-CSharp.csproj and Assembly-CSharp-Editor.csproj with v4.6.1. And I got same result.
Something automatically sets the version of the framework and I don't understand where is the shit.
WTF? Does anybody know anything about it?
Unity doesn't rely on csproj for compilation. csproj is only created for IDEs.
Theoretically you workaround by moving Rider package from whatever it is on your computer to Packages folder, it becomes your locally developed package, then you can change TargetFrameworkVersion https://github.com/van800/com.unity.ide.rider/blob/0a42b224e6191934884de084ccd59348742a2bc6/Packages/com.unity.ide.rider/Rider/Editor/ProjectGeneration/ProjectGeneration.cs#L83

VSCode c# autocomplete not working on an added package

I am trying to build a library on top of and other library / framework.
I am doing this in C#, So at first i create a new project by doing
dotnet new console
Then i add the package which will serve as the basis for my library. I do this in the following way:
dotnet add package Veldrid
This works fine, i see it get added and it is visible in the .csproj
But then when i try to acces a function of a class or even create a new instance of a class from that package i see no autocomplete options what so ever :( But when i type my own class within the project its namespace autocomplete works all fine.
Why doesnt the autocomplete function work for added packages?
Extra information:
i am using a mac,
I have dotnet core 2.2.300 installed,
i am using vscode with the c# extension,
and in my project i have the using Veldrid added so i can use the package.
Let me know if something is unclear or extra information is needed!
side note:
I keep getting the message: Some projects have trouble loading. Please review the output for more details whenever i open a c# project in vscode.
after spending an age of googling and searching i found what was causing the problem for me.
I had unity installed which also installs the mono framework. (for me the mono framework caused all the problems). So i uninstalled unity and the removed the monoframework from my computer (mac) and all was well.
Hope this helps anyone in the future!
If there are better ways of going about this please let me know!

one or more projects require a platform SDK(UAP, 10.0.16299.91)

I am trying to open the UWP project but however because of versioning issue I am not able to load the project. It gives me following error.
However, this version is already installed and even I have tried to install it again. But even after that is again giving me the same error.
I have updated the project version in .csproj file also as below. The version which is mentioned in the screenshot is already installed.
<TargetPlatformVersion>10.0.16299.91</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.16299.15</TargetPlatformMinVersion>
After doing all this it still gives the error as Visual Studio Update Required.
Any help on this appreciated!
Don't try to target your project to 10.0.16299.91 from your csproj, you can specific the target version to 10.0.16299.0 as Jet suggested. The build version is different from target version.
Thinking about this, if your customer is on 10.0.16299.0, then he cannot use your app? This is not reasonable. By the way, when you load your project, it will asks you to retarget your project, you can find the supported target version listed there.

Categories