I am new to C# and I am trying to create a bitmap object in C# in Visual Studio 2019, but it isn't working. I have .NET Framework updated to the latest version and I have resharper installed. I am using Windows 10.
Ive tried adding the references manually with Add/Reference... and it does not stay checked.
I added using system.drawing and using system.drawing.common to the top of my code.
I updated my .net core and enabled it in my project.
using System;
using System.Drawing.Common;
namespace Bot
{
class Program
{
static void Main(string[] args)
{
var bmp = new Bitmap();
}
}
}
I expected it to create a bitmap object, but it won't compile and gives me errors saying that the bitmap object does not exist in system.drawing.
The Bitmap class if part of the assembly System.Drawing.Common.dll, so you need to install System.Drawing.Common via the Nuget Package.
It looks like you don't have the package in your system/project.
In you're project directory or from VScode terminal do this:
dotnet add package System.Drawing.Common --version 6.0.0
then add a reference to the package in you're project
Related
I have a C# project using the ImageMagick library Magick.Net Q16 AnyCPU net40 targeting .Net 4.7.2 using VS 2022. After upgrading this from 7.4.6 to 11.2.1 using Nuget Package Manager the function image.AddProfile (where image is an ImageMagick image) is flagged as not present using the code below:
using (MagickImage image = new MagickImage(sFileIn))
{
image.AddProfile(ExifProfile1);
The function image.AddNoise is present. I have a 'using ImageMagick' statement in the namespace. Looking at the ImageMagick namespace, AddProfile is defined as shown below:
public unsafe void AddProfile(string? name, byte[] datum, int length)
How can I access the AddProfile function in this version of ImageMagick?
You can find your answer in the release notes: https://github.com/dlemstra/Magick.NET/releases/tag/7.16.0.0. The AddProfile method has been renamed to SetProfile.
In plain words I want to be able to modify .csproj files programmatically.
I am developing an application that replaces a nuget package with its actual project reference. This is application is used for debugging purpose. We have a huge set of packages that we add in our solution file. To do that I read a csproj file and apply a regex to find the specifies nuget package reference and add a project reference instead. This part was working, but its not picking the packages anymore.
The above can be done using the dotnet command but using that I cannot replace the old version back.
Is there any Microsoft nuget package available which can read the package references in csproj files?
Similar question is asked here but Build.Engine is not available in the latest version.
Is there any Microsoft nuget package available which can read the
package references in csproj files?
As far as I know, Microsoft.Build.Engine does not support editing New Sdk format projects(Net Core) and is not compatible with this nuget package. This nuget package is just for old sdk format projects(Net Framework) and you cannot edit xml elements of Net Core Projects.
Get nuget package version included in csproj in .Net Core 3.1
Since you want to get Nuget package References and their versions, you could try this function programmatically:
public class PackageReference
{
public string Include { get; set; } //get the nuget reference name
public Version Version { get; set; } // get thee nuget package version
}
static void Main(string[] args)
{
//load the xxx.csproj file
var doc = XDocument.Load("C:\\xxxx\\xxxx\\xxx\\xxx\\xxx.csproj");
var packageReferences = doc.XPathSelectElements("//PackageReference")
.Select(pr => new PackageReference
{
Include = pr.Attribute("Include").Value,
Version = new Version(pr.Attribute("Version").Value)
});
Console.WriteLine($"Project file contains {packageReferences.Count()} package references:");
foreach (var packageReference in packageReferences)
{
Console.WriteLine($"{packageReference.Include}, version {packageReference.Version}");
}
}
Update 1
Just install Microsoft.Build and Microsoft.Build.Utilities.Core in a net framework project and then type these which can set a property in xxx.csproj file as Build.Engine nuget package did.
Note that it should be written in net framework projects rather than net core or net standard projects(which will cause errors).
using Microsoft.Build.Evaluation;
.......
{
class Program
{
static void Main(string[] args)
{
var collection = new ProjectCollection();
var project = collection.LoadProject(#"xx:\xxx\xxx\xxx.csproj");
project.SetProperty("Test","true");
project.Save(#"xx:\xxx\xxx\xxx.csproj");
}
}
}
Hope it could help you.
I have the below snippet of code to test/use dotnet 2.1 in vs 2017 in order to try out and run C# 7.2s Span functionality.
Where can I find the SDK that allows me to run this within Visual Studio.
I can only find frameworks up to 2.0.
using System;
using System.Memory;
namespace sim
{
class Program
{
static void Main(string[] args)
{
var arr = new byte[10];
Span<byte> bytes = arr; // Implicit cast from T[] to Span<T>
Span<byte> slicedBytes = bytes.Slice(start: 5, length: 2);
}
}
}
Otherwise I'm left unable to run and use
Error CS0305 Using the generic type 'Memory' requires 1 type arguments sim
You do not need to install any SDK for using Span<T>
You need to install System.Memory nuget package which is prerelase version.
you can use this command
Install-Package System.Memory -Version 4.5.0-preview2-26406-04
You also need to set your language version to 7.2 in your project properties and also you need Visual Studio 15.5 or more
Have you tried this? .NET Core SDK 2.1.4
I have the C# VSC extension as well as the NuGet Package Manager installed. Here is my VSC version info:
First, I create a brand new console application in VSC with the command:
dotnet new console
This gives me the code:
using System;
namespace ReferenceTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
I now want to create a using System.Windows.Forms; reference. When I start typing this using statement however, intelli-sense fails me:
I found this question/answer already but in step #5 the autofill option shown is not there:
When I try to improvise and follow other instructions I've found in my searching by using the
NuGet Package Manager: Add Package
option, I cannot select System.Windows.Forms
I have looked for a project.json file per the instructions of several sites but I can only find a project.assets.json file and it doesn't look very similar to what I see in the examples I find. This issue is not only for System.Windows.Forms but other references I try as well.
Windows Forms and WPF applications are not supported in .NET Core, only in .NET Framework.
have a look at the following article:
https://stackify.com/net-core-vs-net-framework/
i am trying to install MVVMCross plugin in UWP project but it seems to fail.
in the PCL it seems to be working fine, but in the UWP I'm expecting that the plugin will create a Bootstrap folder and it doesn't happen.
I even started a new project from scratch named it "TipCalc.WindowsUWP", installed the MVVMCross and then the JSON plugin using NuGet and nothing happens.
the output of the plugin installation looks fine:
Restoring packages for 'TipCalc.WindowsUWP'.
Restoring packages for C:\Users\kayce\Documents\Visual Studio 2015\Projects\TenBisServer\MvvmCross\TipCalc\TipCalc.WindowsUWP\project.json...
Package restore completed successfully for 'TipCalc.WindowsUWP'.
Successfully installed 'MvvmCross.Plugin.Json 4.2.3' to TipCalc.WindowsUWP
========== Finished ==========
what I am missing ?
This is expected behavior, as a UWP project uses a project.json (NuGet 3) template. Currently all additional content and scripting specified in the NuGet package with have no affect on your project when including a package (See Changes affecting existing packages).
You will have to manually add the bootstrap folder and relevant plugin bootstrap .cs file, or you can register the interface and implementation of the plugin in your Setup.cs.
Bootstrap Approach:
using MvvmCross.Platform.Plugins;
namespace <<YOUR_NAMESSPACE>>.Bootstrap
{
public class JsonPluginBootstrap
: MvxPluginBootstrapAction<MvvmCross.Plugins.Json.PluginLoader>
{
}
}
Setup.cs Approach:
protected override void InitializeLastChance()
{
base.InitializeLastChance();
Mvx.RegisterSingleton<IMvxJsonConverter>(new MvxJsonConverter());
}