Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all 3172 articles
Browse latest View live

Nuget packaging: Possible to target early frameworks only?

$
0
0

I have some code that works in dotnet 2.0, 3.0, and 3.5 but not in 4.0 and greater. Is there a mechanism within Nuget to target these earlier frameworks only?


Visual Studio 2017 steps into the wrong NuGet package location

$
0
0

I have several C# console app projects referencing different versions of a NuGet package. One application references the 1.2.3 version of the package but VS (Visual Studio 2017) steps into the 1.2.3-CI-20200602-01 version of the package in a different solution folder during a debugging session.

How can I get VS to step into the current solution's packages/MyPackage.1.2.3/src folder?

Things I've tried:

  • Searching for any references to the other solution.
  • Removing the package from the solution and adding it again.
  • Closing VS, deleting the package folder, restoring packages.
  • Deleting the bin and obj folders, cleaning and rebuilding.
  • Emptying the symbols cache under Options > Debugging > Symbols and restarting VS.
  • Clearing all NuGet caches under Options > NuGet Package Manager > General.
  • Deleting the contents of the %TEMP% folder.
  • All of the above before rebooting and rebuilding.

I'm getting close to rewriting the app from scratch, but if anybody knows the location where VS is caching NuGet package references for debug sessions it'll be much appreciated!

Not able validate data condition based on the json element attribute value from a json using c#

$
0
0

I have a json file, where i have to validate a json attribute element value based on another json element attribute value. But if there json elements with the same name. It always takes the last value always instead of parsing the json data fully. Please guide me.

Below the sample json file

{"PLMXML":{"language":"en-us","author":"Developer","date":"2020-05-22","traverseRootRefs":"#id6","Operation":{"id":"id21","subType":"BS4_BaOP","catalogueId":"70700000209604",         },"Operation":{"id":"id28","subType":"BS4_BaOP","catalogueId":"70700000209603",         },"OperationRevision":{"id":"id6","subType":"BS4_BaOPRevision","masterRef":"#id21","revision":"A1",         }      }}

And below the code which im trying to use

public void Readjsonfile(string jsondata){       var message = JsonConvert.DeserializeObject<plmxmldatamodel>(jsondata);          if (String.Equals(message.PLMXML.traverseRootRefs.Substring(1), message.PLMXML.OperationRevision.id))    {           Console.WriteLine("Condtion1");                 if (String.Equals(message.PLMXML.OperationRevision.masterRef.Substring(1), message.PLMXML.Operation.id))        {            Console.WriteLine("Condition_2");            //Do something based on the condtion        }                   }}public class Operation{    public string id { get; set; }    public string subType { get; set; }    public string catalogueId { get; set; }}public class OperationRevision{    public string id { get; set; }    public string subType { get; set; }    public string masterRef { get; set; }}public class PLMXML{    public string language { get; set; }    public string author { get; set; }    public string date { get; set; }    public string traverseRootRefs { get; set; }                public Operation Operation { get; set; }    public OperationRevision OperationRevision { get; set; }}public class plmxmldatamodel{    public PLMXML PLMXML { get; set; }}

When i try to dedug this in the second if condtion, the value for message.PLMXML.Operation.id is always id28 , because of which second if condition fails. While the first if condition is passed as there is only one message.PLMXML.OperationRevision.id. i wanted behaviour where it would check complete json data and check if message.PLMXML.Operation.id with value id21 is present or not , So my data gets passed. Please kindly guide me here.I am very new to C# here.

Why Is Adding Windows Specific Nugets to ASP.NET Core Possible

$
0
0

System.Net.Http.WinHttpHandler Nuget description says that it is Windows specific. But I was able to install it on an ASP.NET core project nevertheless.

Shouldn't it be prevented by Visual Studio to add such Windows specific dependencies to an ASP.NET Core project?

Using LazZiya ExpressLocalization Nuget package to Localize web app

$
0
0

I have been trying to follow these two tutorials to add Localization to my .Net Core Razor web app.

http://ziyad.info/en/articles/36-Develop_Multi_Cultural_Web_Application_Using_ExpressLocalization

https://medium.com/swlh/step-by-step-tutorial-to-build-multi-cultural-asp-net-core-web-app-3fac9a960c43

I have tried creating projects from scratch. I have tried adding to my existing projects. I have tried using the LocalizeTagHelper and SharedCultureLocalizer options without success.

I just cant get any text such as 'Home' or 'myApp' below to change.

When I select a language in my dropdown, the language is specified in the URL (See below), but my text just wont change.

Dropdown component & Home text x 2:

enter image description here

Url:

My Packages:enter image description here

Index.cshtml

@page@model IndexModel@using LazZiya.ExpressLocalization@inject ISharedCultureLocalizer _loc@{    ViewData["Title"] = @_loc["myApp"];}<body><h1 class="display-4" localize-content>Home</h1><header><div class="bg-img"><div class="container-title"><div class="block-title block-title1"><language-nav cookie-handler-url="@Url.Page("/Index", "SetCultureCookie", new { area="", cltr="{0}", returnUrl="{1}" })"></language-nav><br></div><div class="block-title block-title2 d-none d-md-block d-lg-block d-xl-block"><img src="/image/title_image.png" class="img-fluid"></div></div></div></header><main><div class="row_primary"></div></main></body>

Index.cshtml.cs

using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.Localization;using Microsoft.AspNetCore.Mvc;using Microsoft.AspNetCore.Mvc.RazorPages;using Microsoft.Extensions.Logging;namespace myApp.Pages{    public class IndexModel : PageModel    {        private readonly ILogger<IndexModel> _logger;        public IndexModel(ILogger<IndexModel> logger)        {            _logger = logger;        }        public void OnGet()        {        }        public IActionResult OnGetSetCultureCookie(string cltr, string returnUrl)        {            Response.Cookies.Append(                CookieRequestCultureProvider.DefaultCookieName,                CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(cltr)),                new CookieOptions { Expires = DateTimeOffset.UtcNow.AddYears(1) }            );            return LocalRedirect(returnUrl);        }    }}

Startup.cs

using System;using Microsoft.AspNetCore.Builder;using Microsoft.AspNetCore.Hosting;using Microsoft.Extensions.Configuration;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Hosting;using LazZiya.ExpressLocalization;using System.Globalization;using Microsoft.AspNetCore.Localization;using myApp.wwwroot.LocalizationResources;namespace myApp{    public class Startup    {        public Startup(IConfiguration configuration)        {            Configuration = configuration;        }        public IConfiguration Configuration { get; }        // This method gets called by the runtime. Use this method to add services to the container.        public void ConfigureServices(IServiceCollection services)        {            services.AddRazorPages();            var cultures = new[]            {                new CultureInfo("de"),                new CultureInfo("fr"),                new CultureInfo("en"),            };            services.AddRazorPages().AddExpressLocalization<ExpressLocalizationResource, ViewLocalizationResource >( ops =>                {                    ops.ResourcesPath = "LocalizationResources";                    ops.RequestLocalizationOptions = o =>                    {                        o.SupportedCultures = cultures;                        o.SupportedUICultures = cultures;                        o.DefaultRequestCulture = new RequestCulture("en");                    };                });        }        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)        {            if (env.IsDevelopment())            {                app.UseDeveloperExceptionPage();            }            else            {                app.UseExceptionHandler("/Error");                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.                app.UseHsts();            }            app.UseHttpsRedirection();            app.UseStaticFiles();            app.UseRouting();            app.UseAuthorization();            app.UseRequestLocalization();            app.UseEndpoints(endpoints =>            {                endpoints.MapRazorPages();            });        }    }}

wwwroot

enter image description here

resx example

enter image description here

resx properties

enter image description here

Can not delete a nuget package with the dotnet cli

$
0
0

I can not delete a nuget package with the dotnet cli.

Here is the command I am running:

dotnet nuget delete package AutoMapper.Extensions.Microsoft.DependencyInjection 7.0.0

Here is the error I am getting:

error: Source parameter was not specified.

enter image description here

Here is my .csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web"><PropertyGroup><TargetFramework>netcoreapp3.1</TargetFramework></PropertyGroup><ItemGroup><PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" /><PackageReference Include="Braintree" Version="4.17.0" /><PackageReference Include="BraintreeHttp-Dotnet" Version="0.3.0" /><PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.4" /><PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.3"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets><PrivateAssets>all</PrivateAssets></PackageReference><PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.3"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets><PrivateAssets>all</PrivateAssets></PackageReference><PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.5.1" /><PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.3" /><PackageReference Include="PayPalCheckoutSdk" Version="1.0.3" /><PackageReference Include="PayPalHttp" Version="1.0.0" /><PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.5.1" /></ItemGroup></Project>

What am I missing here?

Visual Studio Remove Unused Nuget Dependencies

$
0
0

i am struggeling for a while now with removing unused dependencies from bin output folders. I am for example writing a small .NET Wpf program which gets its data from a Web server. Therefore i installed the System.Net.Http NugetPackage to make my Get / Post requests. The Package Information is stored in the .csproj file. When i compile the project a lot of Dependencies are added to the output folder

  • Sytem.Security.Cryptography.Algorithms.dll

  • Sytem.Security.Cryptography.Encoding.dll

  • Sytem.Security.Cryptography.Primitives.dll

  • Sytem.Security.Cryptography.X509Certificates.dll

  • ...

None of these dependencies are explicitly used in my program, means when i delete them from the output folder and start the application everything works as expected. I do understand that this Dlls has to be in the package, but how can i ignore them. Is there a way to ignore dependencies within a nuget package?

Which .net package (Apache.NMS.AMQP/AMQP.Net Lite) should be used for communication with the ActiveMq broker?

$
0
0

We started using Active MQ Broker on our RedHat platform.

The Instalation is done and we are in the process of creatinga producer/consumer for testing purposes.

Now we need to separate the producer/publisher from the consumer/the subscriber (in .net 2.1).

According to the following suggestion:https://access.redhat.com/discussions/3177401NMS is depricated since september 2017, but still has released nuget packages for Apache.NMS.AMQP(1.8.1) about two months ago.

Our question is should we use the nuget package Apache.NMS.AMQP(1.8.1) or is the nuget package AMQPNetLite.Core preferable (although it does not have all the properties and methods)?


ArduinoUploader NuGet package

$
0
0

I have downloaded the NuGet package Arduino Uploader (https://www.nuget.org/packages/ArduinoUploader/), and receive the following error when trying to run it using the example on the github page (https://github.com/twinearthsoftware/ArduinoSketchUploader) under the .Net package. The code is as follows

var upload = new ArduinoSketchUploader(                new ArduinoSketchUploaderOptions()                    {                    FileName = @"location of the file",                        PortName = "COM7",                    ArduinoModel = ArduinoModel.Micro                    });            upload.UploadSketch();

The error of Exception unhandled occurs on the upload.UploadSketch(); line giving off

ArduinoUploader.ArduinoUploaderException: 'Exception during close of the programmer: 'Object reference not set to an instance of an object.'.'`.The details copied from Visual Studio are `ArduinoUploader.ArduinoUploaderException  HResult=0x80131500  Message=Exception during close of the programmer: 'Object reference not set to an instance of an object.'.  Source=ArduinoUploader  StackTrace:   at ArduinoUploader.BootloaderProgrammers.Protocols.AVR109.Avr109BootloaderProgrammer.Close()   at ArduinoUploader.ArduinoSketchUploader.UploadSketch(IEnumerable`1 hexFileContents)   at ArduinoUploader.ArduinoSketchUploader.UploadSketch()   at arduino_sending_code.Program.Main(String[] args) in C:\Users\User\source\repos\arduino sending code\arduino sending code\Program.cs:line 39  This exception was originally thrown at this call stack:    [External Code]    arduino_sending_code.Program.Main(string[]) in Program.cs

Are there any suggestions to overcome this error?

Which.net package (Apache.NMS.AMQP/AMQP.Net Lite) should be used for communication with the ActiveMQ broker? [closed]

$
0
0

We started using Active MQ Broker on our RedHat platform.

The Instalation is done and we are in the process of creatinga producer/consumer for testing purposes.

Now we need to separate the producer/publisher from the consumer/the subscriber (in .net 2.1).

According to the following suggestion:https://access.redhat.com/discussions/3177401NMS is depricated since september 2017, but still has released nuget packages for Apache.NMS.AMQP(1.8.1) about two months ago.

Our question is should we use the nuget package Apache.NMS.AMQP(1.8.1) or is the nuget package AMQPNetLite.Core preferable (although it does not have all the properties and methods)?

TCP/IP Client and Server basic using and references

$
0
0

I have installed TCP/IP from VS15 NuGet Packeges into my project and in References it is as SimpleTCP, I've rebuild project, but for SimpleTcpClient client; it says:

Suppression State Error CS0246 The type or namespace name'SimpleTcpServer' could not be found (are you missing a using directive or an assembly reference?)

not sure what can be cause of that, maybe I missed some references or even using.

Client:

using System;using System.Text;using System.Windows.Forms;namespace Client{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        SimpleTcpClient client;        private void button1_Click(object sender, EventArgs e)        {            button1.Enabled = false;        }        private void button2_Click(object sender, EventArgs e)        {            client.WriteLineAndGetReplay(txtMessage.Text, TimeSpan.FromSeconds(5));        }        private void Form1_Load(object sender, EventArgs e)        {            client = new SimpleTcpClient();            client.StringEncoder = Encoding.UTF8;            client.DataRecevived += Client_DataReceived;        }        private void Client_DataReceived(object sender, SimpleTCP.Message e)        {            textBox1.Invoke((MethodInvoker)delegate ()            {                textBox1.Text += e.MessageString;            });        }    }}

Server:

using System;using System.Text;using System.Windows.Forms;namespace Server{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        SimpleTcpServer server;        private void Form1_Load(object sender, EventArgs e)        {            server = new SimpleTcpServer();            server.Delimeter = 0x13;            server.StringEncoder = Encoding.UTF8;            server.DataReceived += Server_DataReceived;        }        private void Server_DataReceived(object sender, SimpleTCP.Message e)        {            txtStatus.Invoke((MethodInvoker)delegate ()            {                txtStatus.Text += e.MessageString;                e.ReplyLine(string.Format("You said: {0}", e.MessageString));            });                  }        private void btnStart_Click(object sender, EventArgs e)        {            txtStatus.Text += "Server starting...";            System.Net.IPAddress ip = new System.Net.IPAddress(long.Parse(txtHost.Text));            server.Start(ip, Convert.ToInt32(txtPort.Text));        }        private void btnStop_Click(object sender, EventArgs e)        {            if (server.IsStarted)            {                server.Stop();            }        }    }}

.NET Core NuGet Package from Azure Artifacts cannot resolve namespaces

$
0
0

I create several NuGet Packages using CI/CD and I can successfully import them into my project, but somehow my .NET Core project cannot find the Classes and Namespaces?

So in Azure Artifacts I have the package Common.Helpers:1.0.5:In the Nuget Package Explorer I have:

 - bin   - release      - netcoreapp3.1      - Common.Helpers.deps.json      - Common.Helpers.dll      - Common.Helpers.pdb

Also, I checked with NuGet package explorer, to see if the .dlls are in there and they are.

I just noticed that my nuget package contain the .dll files. But when I do a nuget add to a local directory, it does not extract the dlls?

What else can I do ?

Reference not updated after install

$
0
0

I have recently upgraded my reference packagesMicrosoft.Aspnet.Mvc from 4.0.0 to 5.0.0,Newtonsoft.Json to 6.0.3,Microsoft.Aspnet.WebApi to 5.0.0

And I installed it using NuGet Package Manager Console in Visual Studio 2013. But when I check the version of the references in the solutions explorer, I still see the older version for MVC reference. The other references have been updated.

In the .csproj file I see the Reference include for System.Web.Mvc mentions version 4.0.0.0 but HintPath is for 5.0.0.

I tried the following:

  1. Deleted the packages directory from Windows explorer

  2. Updated package through Package Manager Console, but the problem still persists.

Could someone help me with this?

Edit: Adding one of the reference tags

<Reference Include="System.Web.Mvc, Version=4.0.0, Culture=neutral, PublicKeyToken=12345, processorArchitecture=MSIL"><SpecificVersion>false</SpecificVersion><HintPath>..\packages\Microsoft.AspNet.Mvc.5.0.0\lib\net45\System.Web.Mvc.dll</HintPath></Reference>

As you can see, the Version in the reference is 4.0.0 and that in the hint path is 5.0.0. 4.0.0 is the version I see in the solution explorer.

I also set the specific version tags to True for all the references in question and built the code, but again, when I look at the properties of the reference in solution explorer, I see 4.0.0.

Edit 2: I deleted the reference from the solutions explorer, then References >Add References > Browse> Selected the latest downloaded Reference dll from package directory. The version in reference manager is 5.0.11001.0

Then I looked at the properties of the added reference. It still is 4.0.0

The magic number in GZip header is not correct EF migration

$
0
0

I am using entity migration command likePM> add-migration Test

After; I am getting error "The magic number in GZip header is not correct. Make sure you are passing in a GZip stream."

ReInstall nuget package manager, reInstall vs2012, but not yet solve my problem?How can I solve it.

PM> Add-Migration TestSystem.IO.InvalidDataException: The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.   at System.IO.Compression.GZipDecoder.ReadHeader(InputBuffer input)   ...   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.

Cannot push nuget packages to private GitLab NuGet Repository - getting 404 (Not Found)

$
0
0

I have a problem with the subject. I have a private Gitlab server where we need to setup nuget package repository.

"Packages" feature is enabled in Gitlab, I can open the list of packages, but it is empty, so I assume I need to push packages to it. So I do nuget push and getting this:enter image description here

Nuget config:enter image description here

Initially, I had another issue with authentication and was getting 401 return code, but it was solved, now I am getting 404. I don't have any proxy. I am using the token with access to all scopes:enter image description here

What could be the root cause of this problem?


Expected Nuget package is installed, still getting an error regarding assembly reference

$
0
0

I am working on legacy .net project where we are using one nuget package which is named as "ML.LeadApproval.Contract".So now I did some changes to this leadApproval project and build a new nuget package but when I installed this new package to my legacy project I am receiving build errors as "The type or namespace name 'LeadApproval' does not exist in the namespace 'ML' (are you missing an assembly reference?"

And the weird thing is when I open any file which refer something from this nuget package, error getting vanished from that file but again when build it or try to run it again I am getting same build errors.

It is working fine when I reinstalled the old package.

Not sure what's wrong.Thank you!

Azure Pipeline only push NuGet packages that have new version

$
0
0

I have a single repo that contains multiple DLLs which create separate NuGet packages. I would like to use the Azure DevOps pipeline to publish these packages automatically when the master branch changes via the NuGet pack and push tasks. I do not want to change the assembly version of the Dlls/NuGet packages that do not change. Running my pipeline causes an exception because of the duplicate versions.

After reading Microsoft's documentation page, I tried adding publishPackageMetadata=true but the build still fails.

vs2019 failed to restore packages

$
0
0

for some reason vs2019 keep failing to restore packages. i changed my nuget package settings to "http://api.nuget.org/v3/index.json" and I was able to download the packages necessary. Now all of a sudden when i try to update or download any other packages i get "failed to restore packages".

The error happens when I add a razor index page and when it tried to scaffold then download the nuget package.

enter image description hereenter image description here

Multiple versions of the same reference vs2019

$
0
0

I have MVC project with Npgsql nuget package installed version 3.2.5Now I need to refernce another project to this MVC project that also uses Npgsql package but with newer version 4.1.3

When I use the project reference services in the MVC project I get an error in runtime that could not find Npgsql 4.1.3

Ofcourse its because MVC project knows Npgsql version 3.2.5

Is there anyway to reference the project and force it to use its own Npgsql packcge ?

What is the best way to solve those kind of isses?

Thank you

AutoMapper 9.0.0 to 4.0.4 downgrade restore failed

$
0
0

I have updated the .Net C# project from package reference to NuGet package references. The project uses the AutoMapper 4.0.4 but after the NuGet upgrade, it got upgraded to 9.0.0 version. If I try to downgrade it will throw below error.

enter image description here

After some investigation, i have found that we are using 1 custom NuGet package called Framework and it has the dependency of Automapper 9.0.0 that's why when i try to downgrade it revert it back to 4.0.4.

Upgrading AutoMapper will take a lot of time and i need a quick fix to run the project. Can i have some configuration that lets me use Automapper 9.0.0 for Custom Framework and Automapper 4.0.4 for code?

Viewing all 3172 articles
Browse latest View live