VS Code C# plus .NET SDK binares (not installers) - c#

I have decided to start studing C#.
I have found lightweight IDE — VS Code.
Because C# requires .NET SDK I downloaded last one as binaries (not installer) — I do not want to install any additional SDK on my computer.
I have changed workspace settings to point at preferable SDK version
{
// ... — just hidden part of a path
"omnisharp.dotnetPath": "...\\NetSDK_7_64",
"csharpextensions.useFileScopedNamespace": true,
"omnisharp.sdkPath": "...\\NetSDK_7_64\\sdk\\7.0.102",
"omnisharp.sdkVersion": "7.0.102",
"omnisharp.sdkIncludePrereleases": false,
"omnisharp.dotNetCliPaths": [
"...\\NetSDK_7_64"
]
}
But VS Code keeps trying to use intalled old version in my system:
Executing task: C:\Program Files (x86)\dotnet\dotnet.exe build ...
Is it possible to configure VS Code to use dotnet.exe from unzipped folder?
I have even created a file global.json
{
"sdk": {
"version": "7.0.102"
}
}
But it only causes additional error:
A compatible installed .NET Core SDK for global.json version [7.0.102] from [...\global.json] was not found
P.S.
And yes, I have looked over Internet for the answer on this question and found nothig useful.
More over it is marked as an official place to ask about VS Code

Related

Dotnet: Works in VSCode's OWN TERMINAL, but OMNISHARP: 'dotnet.exe' is not recognized

How is this possible?
I installed .net sdk 6.0.405: dotnet-sdk-6.0.405-win-x64.exe
I can in windows terminal and power shell run: dotnet --version: 6.0.405 ✅
I CAN ALSO IN VSCODE IN ITS BUILTIN TERMINAL, run: dotnet --version: 6.0.405 ✅✅
But in the OUTPUT tab, choosing OmniSharp Log from the dropdown, it says:
[ERROR] A .NET 6 SDK for x86_64 was not found. Please install the latest x86_64 SDK from ...
I switched vscode explorer settings to use external terminal.
And this terminal setting to command prompt:
Terminal › Integrated › Default Profile: Windows
The default profile used on Windows. This setting will currently be ignored if either terminal.integrated.shell.windows or terminal.integrated.shellArgs.windows are set.
I have dotnet in the PATH (and it works in terminals and in vscode's terminal)
I restarted vscode, AND REINSTALLED the dotnettools "C# for Visual Studio Code (powered by OmniSharp)" extension. I went to the online store and from the right column under Resources I downloaded the ms-dotnettools.csharp-1.25.2#win32-x64.vsix to make sure I get the right one. And restarted vscode.
I tried this setting:
Omnisharp: Dotnet Path
Specified the path to a dotnet installation to use when "useModernNet" is set to true, instead of the default system one. This only influences the dotnet installation to use for hosting Omnisharp itself. Example: "/home/username/mycustomdotnetdirectory".
C:/Program Files/dotnet/sdk/6.0.405
And this setting:
Omnisharp: Sdk Path
Specifies the path to a .NET SDK installation to use for project loading instead of the highest version installed. Applies when "useModernNet" is set to true. Example: /home/username/dotnet/sdks/6.0.300.
C:/Program Files/dotnet/sdk/6.0.405
And restarted vscode. And now it says:
[ERROR] Error: Command failed: dotnet.exe --version
'dotnet.exe' is not recognized as an internal or external command,
operable program or batch file.
What? W H A T? lol
What could be wrong? Why isn't it saying where it expected to find it and what to do to locate it? Is there a setting to specify the dotnet.exe path to this C# extension? Does it need always-on internet or something? Does it have DRM? Does it need Edge installed? Wtf?🙂
🙃😭 I just need intellisense; and I've wasted 2h, on only microsoft-owned products.
#Microsoft 0/5 stars
Still don't know why it happens, but here's how to solve it:
The problem was from this: I like to keep all my visual studio code extensions as .vsix files locally in folders so I can remember and get them easily & offline. Sensible enough choice, and I had the correct ms-dotnettools.csharp-1.25.2#win32-x64.vsix for my platform.
But in VSCode, when I install this particular extension via VSIX, even though it succeeds, it can't find .net. If you instead install the extension "normally", ie via vscode's own download, it seems vscode does some extra configuration steps while installing, and probably sets the .net paths correctly or something. Because now it works.
So TL;DR: don't install ms-dotnettools.csharp via vsix, it seems bugged. 😶
Would love to see an answer explaining what's wrong / how to actually do via vsix; but I don't have any more time to debug this rn.

Error: An assembly specified in the application dependencies manifest not found Package:Newtonsoft.Json when deploying .Net core 2.2

I am deploying a .Net core 2.2 console application using self contained deployment and using some 3rd party libraries like(log4net and Newtonsoft.Json). The application is working fine on the system it is developed but not working when deployed to any other system. The below error displays:
C:\Users\shubhamjain\source\repos\Collect\Collect\bin\Release\netcoreapp2.2\win-x64>Collect.exe
Error:
An assembly specified in the application dependencies manifest (Collect.deps.json) was not found:
package: 'Newtonsoft.Json', version: '12.0.2'
path: 'lib/netstandard1.3/Newtonsoft.Json.dll'
I have tried the below things:
Changing the .Net core version from 2.1 and 2.2
changing the version of Newtonsoft.Json from nuget
Updating visual studio 2019
Nothing worked but when I looked to a file ("Collect.runtimeconfig.dev.json" in path C:\Users\shubhamjain\source\repos\Collect\Collect\bin\Release\netcoreapp2.2\win-x64) and change the shubhamjain with the deployed system username, everything works fine.
Now, What I observe that Newtonsoft.Json is depends on file (.runtimeconfig.dev.json) and in order to make it work I have to change the username in this file.
Is there any way to resolve this automatically?
Collect.runtimeconfig.dev.json :
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\shubhamjain\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\shubhamjain\\.nuget\\packages",
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder" ]
}
}
Can you try configuring your json file with using %username% parameter. I am not sure if it is possible to run that way but you can use that parameter in the Command Prompt to get the logged in username.
You can check the link for more detail.
In this case your Collect.runtimeconfig.dev.json will be :
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\%username%\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\%username%\\.nuget\\packages",
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder" ]
}
}
Also you can prepare different configuration files for different environments. Maybe this Microsoft Doc could be helpful about that.

How to use iOS simulator/Android simulator from visual studio for Mac with xamarian.forms

I made mobile app at azure and quickstarted it as xamarian.forms and (after failing to publish downloaded table api application and deciding to edit it in browser) downloaded the client application they provided. Then when I tried to launch it with on (Debug>IPhone 8 Plus iOS 11.2) simulator, it (simulator) started but no application is visible (and nothing unusual is installed).
It shows warnings (could it be relevant?):
Warning MSB3276: Found conflicts between different versions of the same dependent assembly. Please set the "AutoGenerateBindingRedirects" property to true in the project file. For more information, see http://go.microsoft.com/fwlink/?LinkId=294190. (MSB3276)
(For Android simulator it gives some error like:
/Library/Frameworks/Mono.framework/Versions/5.4.1/lib/mono/xbuild/Microsoft/NuGet/Microsoft.NuGet.targets(5,5): Error: Your project is not referencing the "MonoAndroid,Version=v8.0" framework. Add a reference to "MonoAndroid,Version=v8.0" in the "frameworks" section of your project.json, and then re-run NuGet restore.
)
How can I see the ****** application?
Thank you. =)
Open the project.json file in your xxx.Droid project. Change the MonoAndroid version from:
"frameworks": {
"MonoAndroid,Version=v7.1": {}
}
to:
"frameworks": {
"MonoAndroid,Version=v8.0": {}
}
Now, Restore Nuget Packages for your solution.

How do I build a basic C# program in Visual Studio Code? [duplicate]

I have installed the preview version of Microsoft's new code editor "Visual Studio Code". It seems quite a nice tool!
The introduction mentions you can program c# with it, but the setup document does not mention how to actually compile c# files.
You can define "mono" as a type in the "launch.json" file, but that does not do anything yet. Pressing F5 results in: "make sure to select a configuration from the launch dropdown"...
Also, intellisense is not working for c#? How do you set the path to any included frameworks?
Launch.json:
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Cars.exe",
// Type of configuration. Possible values: "node", "mono".
"type": "mono",
// Workspace relative or absolute path to the program.
"program": "cars.exe",
},
{
"type": "mono",
}
Since no one else said it, the short-cut to compile (build) a C# app in Visual Studio Code (VSCode) is SHIFT+CTRL+B.
If you want to see the build errors (because they don't pop-up by default), the shortcut is SHIFT+CTRL+M.
(I know this question was asking for more than just the build shortcut. But I wanted to answer the question in the title, which wasn't directly answered by other answers/comments.)
Intellisense does work for C# 6, and it's great.
For running console apps you should set up some additional tools:
ASP.NET 5; in Powershell: &{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}
Node.js including package manager npm.
The rest of required tools including Yeoman yo: npm install -g yo grunt-cli generator-aspnet bower
You should also invoke .NET Version Manager: c:\Users\Username\.dnx\bin\dnvm.cmd upgrade -u
Then you can use yo as wizard for Console Application: yo aspnet Choose name and project type. After that go to created folder cd ./MyNewConsoleApp/ and run dnu restore
To execute your program just type >run in Command Palette (Ctrl+Shift+P), or execute dnx . run in shell from the directory of your project.
SHIFT+CTRL+B should work
However sometimes an issue can happen in a locked down non-adminstrator evironment:
If you open an existing C# application from the folder you should have a .sln (solution file) etc..
Commonly you can get these message in VS Code
Downloading package 'OmniSharp (.NET 4.6 / x64)' (19343 KB) .................... Done!
Downloading package '.NET Core Debugger (Windows / x64)' (39827 KB) .................... Done!
Installing package 'OmniSharp (.NET 4.6 / x64)'
Installing package '.NET Core Debugger (Windows / x64)'
Finished
Failed to spawn 'dotnet --info' //this is a possible issue
To which then you will be asked to install .NET CLI tools
If impossible to get SDK installed with no admin privilege - then use other solution.
Install the extension "Code Runner". Check if you can compile your program with csc (ex.: csc hello.cs). The command csc is shipped with Mono. Then add this to your VS Code user settings:
"code-runner.executorMap": {
"csharp": "echo '# calling mono\n' && cd $dir && csc /nologo $fileName && mono $dir$fileNameWithoutExt.exe",
// "csharp": "echo '# calling dotnet run\n' && dotnet run"
}
Open your C# file and use the execution key of Code Runner.
Edit: also added dotnet run, so you can choose how you want to execute your program: with Mono, or with dotnet. If you choose dotnet, then first create the project (dotnet new console, dotnet restore).
To Run a C# Project in VS Code Terminal
Install CodeRunner Extension in your VS Code (Extension ID: formulahendry.code-runner)
Go to Settings and open settings.json
Type in code-runner.executorMap
Find "csharp": "scriptcs"
Replace it with this "csharp": "cd $dir && dotnet run $fileName"
Your project should Run in VS Code Terminal once you press the run button or ALT + Shift + N

Build TagLib# DLL from source and make it COM Visible to PHP

Hello I want to scan audio-video files and store their metadata in a database using php. I found this Command-line wrapper that uses TagLib.dll compiled by banshee developpers to do the job. It's works fine but it limited by the functions implemented. I want to access directly to the dll methods via PHP.
In PHP we have a function (DOTNET) that allows me to instantiate a class from a .Net assembly and call its methods and access its properties like this :
/*$obj = new DOTNET("assembly", "classname");*/
$stack = new DOTNET("mscorlib", "System.Collections.Stack");
$stack->Push(".Net");
$stack->Push("Hello ");
echo $stack->Pop() . $stack->Pop();
//Returns string(10) "Hello .Net";
Here is the Taglib# project sources in github
I saw many questions relatives to PHP-DLL-COM and there is some recommendations :
Make the dll comVisible;
Register the dll with regsvr32;
Use a module definition file similar to
;
;
DESCRIPTION "Simple COM object"
EXPORTS
DllGetClassObject PRIVATE
DllCanUnloadNow PRIVATE
DllRegisterServer PRIVATE
DllUnregisterServer PRIVATE
My question is : How can I build the DLL and use its method via PHP ?
My config :
OS
Windows Server 2012 R2 Standard Edition i586
Apache :
Apache/2.2.21 (Win32) DAV/2 PHP/5.4.42 mod_ssl/2.2.21 OpenSSL/0.9.8r
PHP
PHP Version : 5.4.42
Arch : x86
Compiler : MSVC9 (Visual C++ 2008)
COM support : enabled
DCOM support : disabled
.Net support enabled
Microsoft Visual Studio 2013
Give the following steps a try:
Download taglib source code from github
Remove the ApplicationIcon tag from the .csproj file and open .sln in Visual Studio
Unload the test project (you don't need to build this)
Right-click on taglib-sharp project --> properties --> build --> enable 'Register for COM interop'. Also clear the conditional compilation symbols textbox so that you don't have to bother with downloading SharpZipLib for now.
Observe #1: in project properties --> Application --> Assembly information --> 'Make assembly COM visible' is checked
Observe #2: in project properties --> Application --> target framework is set to 3.5 (make sure you leave it as that)
Build the project (F6)
Read the contents of the output window to see some warnings
Now that you have src\taglib-sharp.dll you need to register it into the global assembly cache in order for the DOTNET class to find it. See PHP DOTNET hell for details if you are not familiar with this.
If all is good, you can get yourself a copy of SharpZipLib, and reenter the HAVE_SHARPZIPLIB conditional compilation symbol --> rebuild --> redeploy to GAC --> and be a happy man! :)
You may compile you DLL with .NET Framework 3.5 if not, PHP do not be able to load it via DOTNET class.
Download .NET 3.5

Categories