VSCode - adding c# assembly reference - visual-studio-code

Getting the following error:
The name 'File' does not exist in the current context[dnxcore50]
Tried to build it in-case it was to do with VSCode alone. It threw me same error.
I have installed the dependency using the following:
dnu install System.IO
Gave me the following message
c:\Users\user1\Dropbox\dev\csharp\vscode\ads\WeightedGraphs>dnu
install System.IO
GET https://www.nuget.org/api/v2/FindPackagesById()?Id='System.IO'.
OK https://www.nuget.org/api/v2/FindPackagesById()?Id='System.IO' 679ms
System.IO.4.0.10-beta-22816 was added to project.json.
Restoring packages for c:\Users\user1\Dropbox\dev\csharp\vscode\ads\WeightedGraphs\project.json
Writing lock file c:\Users\user1\Dropbox\dev\csharp\vscode\ads\WeightedGraphs\project.lock.json
Restore complete, 302ms elapsed
project.json
{
"version": "1.0.0-*",
"dependencies": {
"System.IO": "4.0.10-beta-22816"
},
"commands": {
"run": "run"
},
"frameworks": {
"dnx451": {},
"dnxcore50": {
"dependencies": {
"System.Collections": "4.0.10-beta-22816",
"System.Linq": "4.0.0-beta-22816",
"System.Console": "4.0.0-beta-22816"
}
}
}
}
In.cs
using System.IO;
public class In{
public In(string s){
var filename = s;
var path = "";
if(File.Exists(path)){
//Code TO Be Added
}
}
}

You also need to add "System.IO.FileSystem" to your dependencies.

Related

MongoRuntimeError Unable to parse with URL

I am trying to connect to a mongo db using the nodejs mongo driver and I'm doing this in a cypress project. I get the error in the title. Below is the simplified version of my code.
import {MongoClient} from 'mongodb';
export class SomeRepository {
static insertSomething(): void {
// Error in the line below: MongoRuntimeError Unable to parse localhost:27017 with URL
const client = new MongoClient('mongodb://localhost:27017');
}
}
Mongodb is running because I can connect from the terminal. Also tried replacing localhost with 127.0.0.1 and adding the authSource parameter to the connection string.
The reason I'm mentioning cypress is because in a simple node project that only connects to mongodb everything works as expected. Package.json below
{
"name": "e2e",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"cypress": "10.8.0",
"cypress-wait-until": "1.7.2",
"headers-utils": "3.0.2",
"mongodb": "4.10.0",
"otplib": "12.0.1",
"pg": "8.7.3",
"pg-native": "3.0.1",
"typescript": "4.9.3"
}
}
The error is in the way you are passing the url, it is necessary that you follow a pattern, in mongodb to connect you need to have this pattern that I will pass below:
Format:
mongodb://<user>:<password>#<host>
Format with filled values:
mongodb://root:mypassword#localhost:27017/
The reason it’s not working is because you’re calling a NodeJS library in a cypress test. Cypress tests run inside a browser and cannot run nodejs libraries.
If you wanted to execute nodejs code in cypress you must create a cypress task https://docs.cypress.io/api/commands/task#Syntax
// cypress.config.js
import { SomeRepository } from ‘./file/somewhere’
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
on(‘task’, {
insertSomething() {
return SomeRepository.insertSomething();
}
}
}
}
})
// to call in a cypress test
it(‘test’, function () {
cy.task(‘insertSomething’).then(value => /* do something */);
}
});

PHP Composer, command line (CLI) to add a class path to autoload PSR-4 / PSR-0 / file in composer.json

Does Composer have any Command from CLI to add to composer.json such entry?
{
"autoload": {
"psr-4": {
"Monolog\\": "src/",
"Vendor\\Namespace\\": ""
}
}
}
and add this:
{
"autoload": {
"psr-0": {
"Monolog\\": "src/",
"Vendor\\Namespace\\": "src/",
"Vendor_Namespace_": "src/"
}
}
}
and this
{
"autoload": {
"classmap": ["src/", "lib/", "Something.php"]
}
}
and this:
{
"autoload": {
"files": ["src/MyLibrary/functions.php"]
}
}
I looked here:
Composer Command Line Documentation
but haven't found any dedicated command. Perhaps there is a workaround command like:
composer add-entry <key> <value>
or
composer set-key <key> <value>
but I don't know such,
do you know any?
Unfortunately NO. 😢 At least in v1.8.4 and I also want this feature too.
I thought the closest command would be config.
$ composer config bin-dir bin/
$ composer config repositories.github.com '{"type": "vcs", "url": "https://github.com/[YOUR]/[REPO]", "//url": "https://github.com/[YOUR]/[REPO].git"}'
Since this will add the following in composer.json:
"config": {
"bin-dir": "bin/"
},
"repositories": {
"github.com": {
"type": "vcs",
"url": "https://github.com/[YOUR]/[REPO]",
"//url": "https://github.com/[YOUR]/[REPO].git"
}
}
Though, this command seems to work only for "config" and "repositories" keys.
And then I found an issue about this topic. Seems that the community won't add this feature.😭
Yup I don't think we really want to offer this from CLI it's gonna be a bunch of code for very limited use as typically this is done once on package creation.
From: Issue #3398
"[Feature] Adding processing autoloading sections to the command line interface" # GitHub

MissingMethodException on connect with Npgsql + Dotnet CLI on CentOs 7.1

I'm running Dotnet CLI version 1.0.0-rc2-002439 on CentOS 7.1
I've built a prototype Console application that just performs a select against a PostgreSQL 9.4 database.
I'm only targeting DNXCORE50 and on windows, everything works just fine. When I'm running it on CentOS I get the following exception on conn.Open()
Unhandled Exception: System.MissingMethodException: Method not found: 'Void System.Net.Security.SslStream.AuthenticateAsClient(System.String, System.Security.Cryptography.X509Certificates.X509CertificateCollection, System.Security.Authentication.SslProtocols, Boolean)'.
at Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout)
at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout)
at Npgsql.NpgsqlConnector.Open()
at Npgsql.NpgsqlConnectorPool.GetPooledConnector(NpgsqlConnection Connection)
at Npgsql.NpgsqlConnectorPool.RequestConnector(NpgsqlConnection connection)
at Npgsql.NpgsqlConnection.OpenInternal(NpgsqlTimeout timeout)
at Npgsql.NpgsqlConnection.Open()
at SensorBot.Core.Services.ConfigService.GetConfig()
at ConsoleApplication.Program.Main(String[] args)
Here is the project.json I'm using :
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": false
},
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-23811"
},
},
"runtimes": { "centos.7-x64": { } },
"frameworks": {
"dnxcore50": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Console": "4.0.0-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Threading": "4.0.11-beta-23516",
"System.IO": "4.1.0-*",
"System.IO.FileSystem": "4.0.1-rc2-23811",
"System.Runtime.Serialization.Primitives": "4.1.1-*",
"System.Dynamic.Runtime": "4.0.11-*",
"System.Net.Security": "4.0.0-beta-23405",
"System.Net.NetworkInformation": "4.1.0-beta-23405",
"System.Text.RegularExpressions": "4.0.12-rc2-23811",
"Npgsql": "3.1.0-alpha6"
}
}
}
}
I have seen on the npgsql's Github that using https://www.myget.org/gallery/npgsql-unstable as a package source and using the unstable version of Npgsql fixes it but when I use "Npgsql": "3.1.0-unstable0458" the app doesn't compile and says that this version of npgsql is not compatible with DNXCore 5.0.
There must be something I'm doing wrong because other people don't seem to have issues with this any more.
Any ideas ?
I've had the same exception with npgsql version 3.1.0-alpha6
Unhandled Exception: System.MissingMethodException: Method not found: 'Void System.Net.Security.SslStream.AuthenticateAsClient(System.String, System.Security.Cryptography.X509Certificates.X509CertificateCollection, System.Security.Authentication.SslProtocols, Boolean)'.
However I was able to succeed with both versions: 3.1.0-unstable0458 and 3.1.0-unstable0478.
Currently I'm using Centos 7.2, Dotnet CLI version 1.0.0-rc2-002510. As a test application I've created a simple console app with one select to postgresql.
project.json looks like this:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-23811"
},
"Npgsql": "3.1.0-unstable0478"
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50",
}
}
}
Because I use SSL connection to db I had to add few options to my connection string: SSL Mode=Require;Trust Server Certificate=True;Use SSL Stream=True.
Maybe you should try to use a newer version of dotnet cli. If you have any questions about my os/dotnet environment, please let me know.

How can I target .NET35 on OSX using mono and dnx/dnvm?

on Windows using Visual Studio 2015, I can compile a project with dnu build.
The project.json file looks as follows:
{
"version": "1.0.0-*",
"description": "My Class Library",
"authors": [ "Class Library template" ],
"tags": [""],
"projectUrl": "",
"licenseUrl": "",
"tooling": {
"defaultNamespace": "Common"
},
"frameworks": {
"dnx451": { },
"dnxcore50": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-*",
"System.Collections": "4.0.11-beta-*",
"System.Linq": "4.0.1-beta-*",
"System.Runtime": "4.0.21-beta-*",
"System.Threading": "4.0.11-beta-*"
}
}
}
}
After installing mono, dnvm and dnx on a Mac, as per this tutorial, I can actually compile the same project on OSX! This in itself is already pretty awesome!
now, I added the following framework to my project.json file:
"frameworks": {
"dnx35": { }, //"net35"
"dnx451": { },
"dnxcore50": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-*",
"System.Collections": "4.0.11-beta-*",
"System.Linq": "4.0.1-beta-*",
"System.Runtime": "4.0.21-beta-*",
"System.Threading": "4.0.11-beta-*"
}
}
This still compiles on Windows, and produces three sets of dlls, as expected.
However, on OSX it does not build the dnx20 target. Though as far as I understand, the mono compiler mcs can be set to target .net35 by passing in a sdk parameter.
So my question is: Can I target .NET35 with dnx on OSX using mono?
EDIT
The goal of this question is to compile a set of dll's that can be imported into Unity3d. And because Unity3d uses mono as a runtime, I would like to be able to do that by using dnu build, as to be able to develop these dll's on any platform.
You can pass custom Rosyln compiler options via compilationOptions in the project.json file:
"compilationOptions": {
"optimize": true,
"define": ["RELEASE", "TRACE", "PLAYSCRIPT"]
},
Take a look at the various project.json files in the Github aspnet/dnx project, i.e. project.json
But those options are being passed to Rosyln not mcs, Mono is being used as a CLR host for Rosyln's compiler as a service), but I do not believe you are substitute Mono's mcs for that (comments on this anyone?)

Syntax to specify latest pre-release in nuget 3.2rc

I'm trying to configure my project.json file to always download the latest pre-release version of the Roslyn Nightly pacakages.
{
"dependencies": {
"Microsoft.CodeAnalysis.Common": "1.1.0-beta"
},
"frameworks": {
"net452": { }
}
}
This gets me the following version:
WARNING: Dependency specified was Microsoft.CodeAnalysis.Common (≥ 1.1.0-beta) but ended up with Microsoft.CodeAnalysis.Common 1.1.0-beta1-20150812-01.
This is not the newest, which is advertised as:
v1.1.0-beta1-20150906-01
Any suggestions on the correct syntax in the project.json to always get the latest even if it's pre-release? Or is this a bug.
(Source for Roslyn nightly is: https://www.myget.org/gallery/roslyn-nightly)
The following works:
{
"dependencies": {
"Microsoft.CodeAnalysis.Common": "1.1.0-beta1-*"
},
"frameworks": {
"net452": { }
}
}