TargetFrameworkVersion in Assembly-CSCharp.csproj not saving changes - c#

I'm using VS Code as code editor, with c# and unity extensions (to auto-complete functions and variables). When i created unity project, i opened folder of project in vs code - where compiler were throw error (When i cant use fast-fill commands)
[fail]: OmniSharp.MSBuild.ProjectManager
Attempted to update project that is not loaded: w:\projects\2D game\Assembly-CSharp.csproj
I am tried to change file directly, but unity automaticly changing version to 4.7.1, in Unity editor and in project settings i dont found current setting.
In google writes to change TargetFrameworkVerison in csproj file - but i cant to do that. After saving, and opening C# project in unity - changes dont applied, unity automaticly changes version to 4.7.1 (current version .NET Framework is 4.8.1)

Related

Openin unity script in visual studio does not work

I'm having issues to get the latest installment of Unity to work along with it's recommended visual studio 2019. I have a fresh instalation of both of them, done by using the unity hub installer. I create a new project, and make a vanilla c# script and try to open it with visual studio. Visual studio opens, yet there is no project opened, no file shown, not even the project browser pops up.
I have googled a bit and the only recommended sugestion I can find is about making sure that the unity package manager has the Visual Studio package installed which it does have, to the latest version. I don't know what else to do.
I managed to figure out my answer. It seems that what I needed to do was to go into Unity -> Edit -> Preferences -> External tools and select Visual Studio 2019 as my code editor. Then make sure that the Generate csproj file was checked. It seems for some unknown reason that unity does not have this option enabled by default, even though I specified in the Unity Hub installer that I want Visual Studio to be my editor, and I would have expected that all the configurations would have been done automatically.
Unity and VS versions do not match, try changing the VS version (Unity Editor->Edit->Preferences->External Tools->External Script Editor);
Delete the ".vs" folder in the project (this folder is hidden by default, you need to open the hidden files to see it. This folder is boldly deleted, and VS will automatically create it after deletion).
Delete the "Assembly-CSharp.csproj", "Assembly-CSharp-Editor.csproj" and ".sln" files. (Boldly delete, after deleting, VS will automatically create)

Excel Interop build errors with .NET 5

I am porting a .Net Framework 4.7.2 project to .NET 5 and have Excel.Interop build errors that Intellisense has no problem with. I have:
Created a new .NET WPF project
Update the TargetFramework property in the .csproj file from .netcore3.1 to net5.0-windows
Copied my classes over into the new project
Added a reference to the Excel 16.0 Object Library
Changed the Copy Local property of the Interop.Microsoft.Office.Interop.Excel dependency to Yes and changed the Embed Interop Types property to Yes as well
Started a build
The build fails with Interop errors like "'object' does not contain a definition for 'Value'" even though those errors in Intellisense go away after I update the Copy Local and Embed Interop Types properties.
Following the build, if I double-click on each of the build errors, the class file opens and Intellisense considers the error resolved: it disappears from the list and the red line under the code disappears as well.
I see Interop.Microsoft.Office.Interop.Excel in the project Dependencies --> COM expandable items in the Solution Explorer, but when I right click on the Solution, do Properties, and look at Project Dependencies for my project, nothing is listed. Is this a problem? Would a COM reference be listed in Solution Properties --> Project Dependencies?
I was under the impression that the Office Interop libraries would be compatible with .NET 5 and that I am setting things up correctly. Why is does Intellisense think things are fine but build errors result?
Things I've tried
Restarting Visual Studio and my computer
Removing the reference and re-adding it
Cleaning and rebuilding the solution
Deleting the bin and obj folders in the project

My Unity project contains empty compiler errors that stop me from entering play mode. How do I resolve them?

I'm working on a project with a friend, we are using git for version control. They created the unity project and I pulled it to my computer as well. Every time I open the project, I have 2 blank compiler errors. I cannot click on them to open VS because they seemingly do not exist.
I can confirm as well we are using the same unity version (2019.2.15f1) both on Windows machines (mine is Win10)
Here is a list of things I have tried as suggested by other forums and my teammate:
Deleting and recreating library folder (results varied from no effect to unity no longer launching)
Creating a new directory and launching a fresh version (worked correctly on their system, not mine)
Reinstalling Unity
Triple checking that my version is up to date
Reinstalling Unity and Visual Studio
Changing the scripting framework (suggestion was to downgrade from 4 to 3.5, we were already on 2 for some reason)
Edit: Here's a picture of the errors
Edit 2: Attempted to open new project in older version of unity, the following error appeared
Edit 3: Upgraded to Unity v 2020.1.0a14
Edit 4: Never mind, now it's not even letting me open the project anymore. Complete with a cool fun new error.
Edit 5: It just... started working. I reinstalled unity again and it just decided to work.
It seems that your project use some packages that aren't installed in your project.
Try to re import the packages mentioned in this image:
enter image description here

How to get intellisense in Visual Studio Code for Unity functions names?

I am following a tutorial about Unity and I see that the instructor has intellisense when writes the method's name.
However I have only intellisense with classes and variables, I mean Unity classes like Rigidbody and my own variables.
I have also read:
Autocompletion not working in Visual studio
How to enable intellisense in Visual Studio 2017 for Unity
Old question, but I had the same problem just recently.
There must have been an issue in your Assembly-CSharp.csproj or project-name.sln files. Most likely to be the .csproj file. If you take a look at it, you will see various references to .dll files.
You can tell Unity (my version: v2019.2.20f1) to create these for you by enabling Edit > Preferences > Generate all .csproj files.
1. Delete both files.
2. Enable .csproj file generation.
3. Double click on a script in Unity.
This fixed my issue.
I would really like to clear things up a bit for everyone trying to get Intellisense working with Visual Studio Code.
First of all I am writing this for Unity 2019.4.14 (edit: also for 2020.3 and 2021.3).
These are the things you MUST do for this to work:
You need Visual Studio Code (duh)
You need .NET SDK. I don't think it matters which version, latest is the best I guess. Make sure you install the SDK, not the runtime.
Check if you have .NET SDK installed by typing dotnet in the VSCode terminal.
You also need The .NET Framework Dev Pack because otherwise VSCode is going to be throwing this error:
The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application.
In VSCode search for the 'C# for Visual Studio Code' extension and install it
In Unity go to Package Manager and install Visual Studio Code Editor. This will enable Unity to generate proper project files for VSCode. (might be already installed)
In Unity go to Edit -> Preferences -> External Tools and choose VSCode from the dropdown (could be listed as code.cmd) and after you choose it tick all the checkboxes you want in the Generate .csproj files for section. I checked Embedded Packages, Local Packages, and Packages from unknown sources. Click 'Regenerate project files'
Open any C# file from Unity and you should be good to go. (you might need to restart VSCode after regenerating project files in order for this to work)
Now, what about Unity Code Snippets and Debugger for Unity extensions? Well these are useful helper extensions but they have nothing to do with Intellisense. The first is for quickly typing common Unity patterns and the second is for showing Unity Debug warnings and errors as you type instead of saving and going back to Unity and reading the console.
Hope this was of any help.
p.s.
One more note: Visual Studio Code depends on the solution files we generate through Unity for Intellisense to work. This is important because you have to add the entire project folder to VSCode workspace and not just Assets folder or your Scripts folders. If you add only the Assets folder to VSCode it won't be aware of those solution (.sln) files. If you open scripts through Unity it will probably work regardless.
Although the answer by Alex Myers is helps, its not 100% right. Unity Snippets does give you some snippets, and the illusion of typeahead, it's not actually intellisense.
For true intellisense you need to:
install dotnet on your system (https://code.visualstudio.com/docs/languages/dotnet) and,
install the dotnet extension for VSCode (https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp)
More information can be found here: https://code.visualstudio.com/docs/languages/dotnet
You can test you have dotnet installed by typing dotnet into the terminal within VSCode.
Note In the image below how I get a full method signature, reference counts, and the yellow hint globe. These are only available when using dotnet + extension (and not available when using the snippets)
Note: my solution does not solve intellisense to function names, but this was the first question that come in fixing intellisense more generally in VSCode.
I needed to update the VSCode package in unity.
In Unity, click Window, then Package Manager, then look for Visual Studio Code Editor. Expand it by pressing triangle, and upgrade to the latest version (for me, it was 1.2.0. I restarted VSCode and it worked.
v1.1.4 had a bug that caused this problem, and was not fixed for about 3 months. It is still the default package installed with a new default project, so you have to change this package version to 1.2.0 in every new project, until they update it.
Check out the guide for Unity Development with VS Code. They recommend a few extensions:
Unity Snippets
Debugger for Unity
Unity Tools
I believe the Unity Snippets extension is what you are looking for.
For anyone having the same problem on a Mac, try setting this value in your .vscode/settings.json (or in the user settings instead of the workspace settings)
"omnisharp.useGlobalMono": "always"
For me just in Unity, Edit/Preferences/External Script Editor, and changed it to My_Install_Location\Microsoft VS Code\Code.exe (maybe hit Regenerate Project Files)
Sorry, I don't have good English, but I'll show you what worked for me.
I opened the C # script in Visual Studio Code and looked for the Assembly-CSharp.csproj file, then, on line 16, I changed the following:
<TargetFrameworkVersion> v4.5 </TargetFrameworkVersion>
For:
<TargetFrameworkVersion> v4.5.1 </TargetFrameworkVersion>
This solved the Intellisense issue.
Intellisense is a pure workflow of .Net Environment. So, you need to have .Net 'Developer pack' (not Runtime) installed on your system as it installs all three necessary components below:
.Net framework
.Net Target pack
.net SDK
reference link: https://dotnet.microsoft.com/download/visual-studio-sdks
It is directly installed to a system admin-accessible path, so no need setting it up. Now, you have to tell VS Code which .Net version to use (whichever you have installed).
Your Unity project will have these two files in the root directory:
Assembly-CSharp.csproj
Assembly-CSharp-Editor.csproj
In these both files search for line (probably 16):
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
Edit version that you had just installed (I had 4.8). Then reopen VS Code. Now everything should work fine.
I found another solution since none of the other solutions were working for me and i was searching for hours.(07/08/2021):
I got the feeling i found the solution for a lot of people since i reinstalled windows recently and simply downloaded everything needed to start without other problems.
I got the same error with .NET, .NET Core or .NET Framework, here are some screenshots of the errors:
In the error output, it says to install the Developer Pack for this framework version. You can find the version in the .csproj file:
By installing the .NET Framework of this version on the dotnet microsoft site: .NET Framework download list
i fixed the error after reloading VSCode and got my Intellisense working for Unity.
TLDR:
My fix was too install .NET Framework version 4.7.1
If you still can't enable IntelliSense, make sure you have VS Code opened in the same directory as the .sln file (I had mine opened deeper in the Assets before).
Source:
https://code.visualstudio.com/docs/other/unity
Though the question is 2 years old, the problem pops up occasionally, just like happened to me.
I had the issue myself, so this one is possibly the first that should be checked.
"Install .NET Framework 4.6 Targeting Pack"
WHY?
First of all, I work with dotnet core, not the standard, so I don't have standard libraries installed on my computer. When I started trying Unity, and VS Code with it, this was the missing part I wasn't aware of.
When I hit the issue, I searched the net a while and see this question. Took me another while to notice this framework sentence in "Enabling code completion" section of VS Code and Unity page. So I tried and now I am happy I tried.
Just don't forget you need to restart at least VS Code to get the intellisense working.
PS: Framework version may, and will most possibly, be changed depending on what year we are in, and which versions we use. So if "4.6" is not working then you probably need another version.
PS2: If it is Mac you are looking for, follow the same link above and find the same section I mentioned above to get a link for .NET SDK.
Follow these steps:
Go into your Unity project.
Go to Edit.
Go to Projects preferences.
Go to External tools.
In line "External Script Editor" you have to change to "Visual Studio Cummunity 2019..."
then it should work.

Error CS2001 Source file 'C:\Users\Admin\Documents\MyHololens01\Packages\com.unity.textmeshpro\Scripts\Runtime\TMP_FontAsset.cs' could not be found

I have installed Hololens Emulator, Visual studio 2017, and Unity 3D and done all the necessary settings.
Now I want to run my Unity project on Hololens Emulator, but unfortunately when I am running the .sln generated file in Visual Studio, I am facing this error:
Error CS2001 Source file 'C:\Users\Admin\Documents\MyHololens01\Packages\com.unity.textmeshpro\Scripts\Runtime\TMP_FontAsset.cs' could not be found
How can I solve this problem?
I encountered the same issue. I am not sure which unity version are you using, but this is what I did to resolve my error (assuming you are using Unity 2018.2.12f1 or 2018.2.11f1):
(1) Uninstall TextMesh Pro
Open your Unity project.
Click on Windows from the Unity Menu
Select Package Manager
Find TextMesh Pro package and select it
Click on Remove located on the top right corner
Screenshot here to help you. I already uninstalled mine, so you should see Remove instead of Install
(2) You must delete the previously generated UWP Visual Studio Solution in your previous build.
(3) Build your project in Unity
(4) If using older version of Unity:
If you see a folder named TextMesh Pro inside your Asset folder, delete it and then follow the steps above to rebuild it. Make sure you delete the previously generated UWP solution.
Hopefully this resolve your issue.

Categories

Resources