Omnsharp's Intellisense not working - c#

I'm on Windows 8.1, using VS Code 1.0.0 and C# for VS Code version 1.0.1-rc2.
The problem is that I can't get Intellisense to work when opening C# projects, but when developing extensions, I do have intellisense enabled.
One thing though, is that when VS Code opens, Omnisharp starts...but, there is an error:
[INFO] Starting OmniSharp at 'c:\dev\TestI'... [ERROR]
Error: connect ETIMEDOUT 192.30.252.126:443
This is my project.json file:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002392"
}
},
"frameworks": {
"netcoreapp1.0": {}
}
}
I also have "http.proxy" set up already.
Any help is appreciated.
Thanks.

Just in case someone has the same problem. Altough it doesn't seem to be a proxy problem there are manual steps to solve the issue.
Go to, https://github.com/OmniSharp/omnisharp-roslyn/releases/ and download the version of omnisharp you need. Unpack it, add a new item in the VS Code preferences: "csharp.omnisharp": "path/to/where/you/unpacked/the/files/".
Restart VS Code.
Taken from: https://github.com/OmniSharp/omnisharp-vscode/issues/200

First,you should download omnisharp-win-x64-netcoreapp1.0.zip from https://github.com/OmniSharp/omnisharp-roslyn/releases, then unzip to C:\tmp\omnisharp-win-x64-netcoreapp1.0.You will get file C:\tmp\omnisharp-win-x64-netcoreapp1.0\OmniSharp.exe。
setting vscode config for c# Intellisense prompt。
Open vscode menu “File ”->"Option”->"setting", you can edit file settings.json.Add newLine
go to:http://www.freemanwoman.com/running-c-aspnet-core-rc2-in-visual-studio-code-with-the-latest-omnisharp-plugin

Related

Error in Visual Studio Code Dotnet Core C#: "The type or namespace name 'System' could not be found", but build succeeds

When trying to work with Visual Studio Code on a C# DotNet Core MVC application, I am having a lot of trouble getting visual studio code to work. It is having trouble finding anything related to C#, marking even 'Using System;' as invalid, saying it can't find it.
However, when I run a Dotnet build, it succeeds with no warnings or errors and the project runs.
My project.json:
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.1.0",
"type": "platform"
},
"Microsoft.EntityFrameworkCore.Sqlite": "1.1.0",
"Microsoft.EntityFrameworkCore.Design": {
"version": "1.1.0",
"type": "build"
},
"Microsoft.AspNetCore.Mvc": "1.1.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
"Microsoft.Extensions.Configuration.Json": "1.1.0",
"Microsoft.Extensions.Logging": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.1.0",
"Microsoft.Extensions.Logging.Debug": "1.1.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
"Microsoft.AspNetCore.StaticFiles": "1.1.0"
},
"frameworks": {
"netcoreapp1.1": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
}
},
"imports": "dnxcore50"
}
}
}
Any ideas? I'm really pulling my hair out with this one.
Sometimes C# for Visual Studio Code (powered by OmniSharp) becomes confused.
Try restarting OmniSharp. Here are two ways:
Close and re-open Visual Studio Code, or
Open the Command Pallet and type Restart Omnisharp.
OmniSharp tends to become confused if we restore dependencies from the command line instead of from within Visual Studio Code.
In VS Code on Fedora 30 with .NET Core 3.0 I had the same issue after create a worker project with dotnet new worker
First issue was that OmniSharp server didn't find the Sdks folder and the solution was include this line to the ~/.bashrc:
export MSBuildSDKsPath="/usr/share/dotnet/sdk/$(dotnet --version)/Sdks"
then restart VS Code, but C# extension show me some messages like:
The type or namespace name 'Collections' does not exist in the namespace 'System' (are you missing an assembly reference?)
the solution was, first, in the terminal run:
dotnet build
then restart the OmniSharp server using the command palette (Ctrl+Shift+P):
OmniSharp: Restart OmniSharp
then I restart VS Code and the C# extensions and all dependencies are working fine.
Ok, I've figured out what was causing the issue. I was referencing the wrong imports for the framework part of the project.json file.
This:
"frameworks": {
"netcoreapp1.1": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
}
},
"imports": "dnxcore50"
}
}
Should be this:
"frameworks": {
"netcoreapp1.1": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
}
I'm on a windows 8 machine, and for some reason "dnxcore50" isn't valid, but "dotnet5.6" and "portable-net45+win8" is. I'm going to keep looking at the why for this question, but I am posting this answer now in case someone else is dealing with this problem.
If you get this error, you could be missing a package.
“The type or namespace name 'System' could not be found”
To add a package, you can run this command in the terminal:
dotnet add package
Example: Add Newtonsoft.Json NuGet package to a project:
dotnet add package Newtonsoft.Json
After that, go to the squiggly line, and add the missing reference by clicking on the lightbulb.
You can also install the Nuget Package Manager extension to find out what packages you need. See this answer to find out more:
Install a Nuget package in Visual Studio Code
I'm using VS Code in a mac with OmniSharp and mono and the issue was gone after doing the following:
For MacOS and Linux users who have Mono installed, this means you will need to set omnisharp.useGlobalMono to never until a version of Mono ships with MSBuild 16.7.
In my case vscode showed this error only for one file. The problem was solved by adding the missing file to the Assembly-CSharp.csproj I'm not sure when files are automatically added and when I do have to do it manually, but it solved this issue.
...
<ItemGroup>
<Compile Include="Assets/Scripts/data/MissingFile.cs" />
...
Same issue happened to me lot of times ..
in my case i opened the visual studio code as admin
then run the teriminal command donet buid
if required Restart OmniSharp (ctrl +shift + p)
Then It's working fine !!!
Another possible cause of getting errors regarding "using System" is storing the .vscode directory in the git repository (my not adding it to .gitignore).
Opening the solution folder with VSCode can create cross version problems like the above and can be solved simply by deleting the .vscode directory.

FxCop Analysis with .Netcore library failed in VS2015 update 3

I was built my project(Class Library) in .Net core and trying to analyze my code using FxCop in VS2015.
But i am getting following error:
"could not identify platform for project"
Also i tried to set platform for my project. But i can't able to set it.
Any thing i missed here?
thanks,
Suresh
By referring this link Use code analysis with Visual Studio DNX project (.xproj)
I have added following lines in project.Json file now its working.
"frameworks": {
"net46": {
"buildOptions": {
"define": [ "CODE_ANALYSIS" ]
}
},
"netstandard1.6": {
"imports": "dnxcore50"
}
}
Note: After added the code in project.json file, close all visual studio application and start it. Then it will work.

Why does .Net Core CLI in VSCode put release folder in the debug directory

I feel like I'm missing something obvious, but searching google, this site and the .Net Core SLI issues section on GitHub did not immediately return an answer, nor did reading the documentation for the .Net Core project.json format.
In plain old C# projects (regular .Net, not Core) scaffolded by Visual Studio (not VSCode), usually running a build will put files in
%project root%/bin/Debug
out of the box, or
%project root%/bin/Release
if you choose publish.
In VSCode with .Net Core, by default build puts files in
%project root%/bin/Debug/netcoreapp1.0.
however if you run
dotnet publish
on the command line, it will put the files in a release folder inside
%project root%/bin/Debug/netcoreapp1.0.
resulting in a structure like
%project root%/bin/Debug/netcoreapp1.0/release.
If you have specified to build for a specific platform target in your project.json then it will similarly put the files in
%project root%/bin/Debug/netcoreapp1.0/PlatformName.
For example
%project root%/bin/Debug/netcoreapp1.0/win7-x64.
My question is, why does .Net Core put the release folder inside the debug folder and since I prefer the old directory structure, is there a way I can tell .Net Core to do it that way instead, say via some project.json property or cli flag similar to how say typescript allows you to specify an outDir?
Testing this with the default hello world project provided by 'dotnet new', my modified project.json looks like this:
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
//"type": "platform",
"version": "1.0.0"
}
},
"imports": "dnxcore50"
}
},
"runtimes": {
"win7-x64": { }
}
}
According to the documentation (bold is mine):
dotnet publish [--framework] [--runtime] [--build-base-path] [--output] [--version-suffix] [--configuration] []
...
-c, --configuration [Debug|Release]
Configuration to use when publishing. The default value is Debug.
So you need to use:
dotnet publish -c Release
(there's also the --output parameter to specify the destination folder: the documentation also states the default, which matches what you are seeing)

Errors when trying to use netstandard with Xamarin forms

So I've been trying to make a project that will use netstandard class libraries common code however I have been unsuccessful as I keep running into errors. I have been following the post here https://oren.codes/2016/07/09/using-xamarin-forms-with-net-standard/ and https://xamarinhelp.com/dot-net-standard-pcl-xamarin-forms/ on how to do it. His sample I can download and run fine but when I try replicate it with his instructions I run into the error
Your project is not referencing the ".NETPortable,Version=v4.5,Profile=Profile111" framework. Add a reference to ".NETPortable,Version=v4.5,Profile=Profile111" in the "frameworks" section of your project.json, and then re-run NuGet restore. FixMyCity.Mobile C:\Program Files (x86)\MSBuild\Microsoft\NuGet\Microsoft.NuGet.targets 140
Which I know it sounds obvious; just add .NETPortable,Version=v4.5,Profile=Profile111 in the frameworks section of project.json but then I get this error (80% certain it's caused by adding it in since it's not there otherwise)
Packages containing MSBuild targets and props files cannot be fully installed in projects targeting multiple frameworks. The MSBuild targets and props files have been ignored. ...project.nuget.targets
Also when I look at the sample project, he does not target .NETPortable,Version=v4.5,Profile=Profile111 and it works fine
This is the closest I've gotten with it so far if you would like to take a look: https://github.com/Toxicable/XamarinFormsNetstandardIssue
It's just the template project (Xamrin forms protalble) with the steps below applied
Run `PM> Uninstall-Package xamarin.forms -Force -RemoveDependencies on each project; IOS and Andriod first PCL last.
Restart VS as prompted by console
Add in project.json to each project as below
Try build but well it wont
PCL project.json
{
"supports": {},
"dependencies": {
"Xamarin.Forms": "2.3.0.107",
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.1": {
"imports": "portable-net45+win8+wpa81+wp8"
},
".NETPortable,Version=v4.5,Profile=Profile111": {}
}
}
project.Driod project.json
{
"dependencies": {
},
"frameworks": {
"MonoAndroid,Version=v6.0": {
}
},
"runtimes": {
"win": {}
}
}
project.iOS project.json
{
"dependencies": {
},
"frameworks": {
"Xamarin.iOS,Version=v1.0": {
}
},
"runtimes": {
"win": {}
}
}
I downloaded your project and noticed that the Xamarin Forms Portable Library was looking a little odd, you would normally see the Xamarin Forms and .NET Standard Library in your references with the blue icon.
I am not sure how it happened but here is how you fix it.
Remove ".NETPortable,Version=v4.5,Profile=Profile111": {} from your project.json.
Unload your project
Edit the project file
Remove this line <TargetFrameworkProfile>Profile111</TargetFrameworkProfile>
Change v4.5 to v5.0 <TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
Save the file and reload the project and it now builds without the need for Profile111 and will also show the references

Why can't I use embedded resources (resx) when targeting .netstandard 1.3?

(Question subtitle: Are resources not supported in .netstandard 1.3 or is my project file just messed up?)
I just created an example portable class library in Visual Studio 2015 Update 3 and added a sample resource file. Initially, the file project.json looks like this:
{
"supports": {
"net46.app": {},
"uwp.10.0.app": {},
"dnxcore50.app": {}
},
"dependencies": {
"Microsoft.NETCore": "5.0.0",
"Microsoft.NETCore.Portable.Compatibility": "1.0.0"
},
"frameworks": {
"dotnet": {
"imports": "portable-net452+win81"
}
}
}
Fine: No compile errors!
After that, I used the project properties to target .NETStandard 1.3.
Now project.json looks like this:
{
"supports": {},
"dependencies": {
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.3": {}
}
}
Now I get the following build error - which means basically the the build action EmbeddedRessource is not supported:
I'm really no expert with project.json, but for me the things look inconsistent - and I have no idea, where the problem is.
in the first project.json: if I support net46, why is it importing net452?
in the second project.json: if I use netstandard1.3, why is there a dependency to the library in version 1.6?
and finally, what is .NETPortable, Version=v5.0? The renaming of .NET Core has taken place early this year - why are we still referencing version 5.0? Even MSDN doesn't know <TargetFrameworkVersion>5.0</TargetFrameworkVersion> which is specified in the csproj
For me, this seems like netstandard isn't only about the available libraries, tooling seems involved, too. But that does not explain, why it worked for dnxcore50.
You need Diagnostics.Tools and Resources.ResourceManager.
I got this working (for .NET Standard 1.4 though) by installing the pre versions, at this time:
"System.Diagnostics.Tools": "4.3.0-preview1-24530-04"
"System.Resources.ResourceManager": "4.3.0-preview1-24530-04"

Categories