Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow

Is there anyway to use the AddSecretClient DI extension in an azure function?

$
0
0

I'm trying to configure some depedancies for my azure function. I need to be able to access (among other things) an azure keyvault. Currently I'm accessing this manually and having to do all my own dependancy injection. This didn't feel right and I went looking for a better way to hook this up. I found this blog that seems ideal.

public void ConfigureServices(IServiceCollection services){  services.AddAzureClients(builder =>  {    // Add a KeyVault client    builder.AddSecretClient(keyVaultUrl);    // Add a storage account client    builder.AddBlobServiceClient(storageUrl);    // Use the environment credential by default    builder.UseCredential(new EnvironmentCredential());  });  services.AddControllers();}

Great I want to do that. Problem is these extensions don't seem to support the particular DI implemented in Azure functions. Specifically there is an incompatibility between the type expected for the AddSecretClient and the builder injected into the Configure(IFunctionsHostBuilder builder):

[assembly: FunctionsStartup(typeof(Startup))]namespace Snapshot.Take{    [ExcludeFromCodeCoverage]    public class Startup : FunctionsStartup    {        public override void Configure(IFunctionsHostBuilder builder)        {            RegisterHttpClients(builder);            builder.Services.AddLogging();            //error            builder.AddSecretClient(new Uri(""));       }   }}

The type'Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder'cannot be used as type parameter 'TBuilder' in the generic type ormethod'SecretClientBuilderExtensions.AddSecretClient(TBuilder,Uri)'. There is no implicit reference conversion from'Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder'to 'Azure.Core.Extensions.IAzureClientFactoryBuilderWithCredential'.

So is there an Azure function version of these extensions or do I have to roll my own?


Sign internal assemblies of a nuget package with Microsoft's Trusted Signing

$
0
0

Presently hosting NuGet artifacts internally using Azure DevOps, but need to sign the contents (signing the NuGet Package itself is not required). Currently the following pipeline task is used to generate the NuGet package:

- task: DotNetCoreCLI@2  displayName: 'Build Nuget Package'  inputs:    command: 'build'    projects: '$(solution)'    arguments: '-c $(buildConfiguration)'

But this automatically generates the *.nupkg file, inside are several assemblies for various runtimes that need to be signed. How can Microsoft's Trusted Signing be used to do this?

NuGet CLI throw error Unable to find .nupkg

$
0
0

I try to build a package using NuGet CLI. I run next command :

.\nuget.exe pack D:\projects\CloudStorage.Client.csproj -OutputDirectory D:\packages -Build -Symbols -Properties Configuration=Release;

But always get next error:

Error NU5012: Unable to find 'Autofac.4.9.4.nupkg'. Make sure the project has been built.

But the solution is built.

I'm using the latest version of NuGet (v5.2.0)

In bin/Release folder Autofac is present or I don't understand correctly of the difference between missed '.nupkg' and present assemblies?

enter image description here

Also for the mentioned project, there are present CloudStorage.Client.nuspec file


This issue was detected when I updated one nuget package(https://www.nuget.org/packages/Z.EntityFramework.Extensions/) in solution that requires now SemVer 2.0.0 package... In order to build it, I upgrade Nuget to 4.3.0+ version. The result is above.


Project nuspec content:

<?xml version="1.0"?><package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"><metadata><id>CloudStorage.Client</id><version>$version$</version><description>CloudStorage Client</description><authors>MyTeam</authors><tags>$branch$</tags></metadata></package>

UPD

I've created test project, where include Autofac 4.9.4 and try to build pack for it. It was successfully created. From console I see that for Autofac was copied all 3 files to bin folder .pdb, .dll and .xml files... while in my "problem" project only .dll is copied.

Azure function. 'Could not load type 'Microsoft.Azure.WebJobs.ParameterBindingData' from assembly 'Microsoft.Azure.WebJobs, Version=3.0.34.0'

$
0
0

I'm trying to run an Azure Function v4 from Visual Studio, I know the function is correct because it works correctly in other computers from the same repo. I already removed and Clone the solution but still it won't work, the error is:"A host error has occurred during startup operationMicrosoft.Azure.WebJobs.Extensions.Storage.Blobs: Could not load type 'Microsoft.Azure.WebJobs.ParameterBindingData' from assembly 'Microsoft.Azure.WebJobs,Version=3.0.34.0"

I noticed that the exception says that I'm using version 3.0.34.0 from Microsoft.Azure.WebJobs although I installed the Version 3.0.37 using Nuget Manager

enter image description here

also the reference in the .csproj indicates it is 3.0.37

enter image description here

I already cleaned, rebuild, eliminated the bin and obj folders and it keeps showing the same error

enter image description here

I also looked for any "3.0.34.0" version of anything but couldn't find any, not sure why it says that version is being used, I even tried to downgrade to that version but it is the only one that doesn't exists and that was really frustrating

enter image description here

Please, help me

Nuget Package include runtimeconfig

$
0
0

I have a Dotnet exe application (App1) which I am trying to create a nuget package.

This package is used in another application(App2) which includes the above Nuget Package and invokes its dll's. This applicaiton is run in a docker linux container.

When Creating the Nuget Package for App1 I am trying to include the deps.json and runtimeconfig.json file in the .nuspec file. I am including these files as it is required in the container to run

<?xml version="1.0"?><package ><metadata></metadata><files><file src="bin\Release\net6.0\abc.net.dll" target="lib\net6.0" /> <file src="bin\Release\net6.0\asdfsd.net.dll" target="lib\net6.0" /> <file src="bin\Release\net6.0\derty.net.dll" target="lib\net6.0" /> <file src="bin\Release\net6.0\eredsww.net.dll" target="lib\net6.0" /> <file src="bin\Release\net6.0\app.net.deps.json" target="contentFiles/any/any" /><file src="bin\Release\net6.0\app.net.runtimeconfig.json" target="contentFiles/any/any" /></files></package>

The consuming application fails when doing a build because of the content files.

What is the correct way to include deps.jsong and runtimeconfig json to the consuming applicaitons

How to include referenced projects

$
0
0

I have a solution with 4 projects inside. One of them we pack as a Nuget package, the others are just some common code shared between the projects. We want to publish the package but we do not want to publish a separate packages for every dependent project.

I tried following this tutorial, and I took the .csproj approach.Here is what I have in the .csproj file on the project that I pack:

<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>net8.0</TargetFramework><Title>LookupListCache</Title><Authors>Yulian Dimitrov</Authors><Description>This package contains everything for setting up a LookupListCache. Please configure LookupListCache connection string.</Description><PackageReleaseNotes>        Some release notes</PackageReleaseNotes><GeneratePackageOnBuild>true</GeneratePackageOnBuild><Version>9.0.0-pg-03</Version><AssemblyVersion>9.0.0.0</AssemblyVersion><FileVersion>9.0.0.0</FileVersion><TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput></PropertyGroup><ItemGroup><PackageReference Include="EFCore.NamingConventions" Version="8.0.3" /><PackageReference Include="AutoMapper" Version="13.0.1" /><PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" /><PackageReference Include="Hangfire.Core" Version="1.8.6" /><PackageReference Include="LEXolutionServiceBus" Version="1.5.175.63106" /><PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" /><PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8"><PrivateAssets>all</PrivateAssets><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets></PackageReference><PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" /><PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" /><PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" /><PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" /><PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" /><PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.8" /><PackageReference Include="Newtonsoft.Json" Version="13.0.3" /></ItemGroup><ItemGroup><None Remove="appsettings.json" /><EmbeddedResource Include="appsettings.json" /></ItemGroup><ItemGroup><ProjectReference Include="..\LookupListCache.Common\LookupListCache.Common.csproj" PrivateAssets="All" /><ProjectReference Include="..\LookupListCache.Migrations.CamelCase\LookupListCache.Migrations.CamelCase.csproj" PrivateAssets="All" /><ProjectReference Include="..\LookupListCache.Migrations.SnakeCase\LookupListCache.Migrations.SnakeCase.csproj" PrivateAssets="All"/></ItemGroup><Target Name="CopyProjectReferencesToPackage" DependsOnTargets="BuildOnlySettings;ResolveReferences"><ItemGroup><!-- Filter out unnecessary files --><_ReferenceCopyLocalPaths Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->WithMetadataValue('PrivateAssets', 'All'))"/></ItemGroup><!-- Print batches for debug purposes --><Message Text="Batch for .nupkg: ReferenceCopyLocalPaths = @(_ReferenceCopyLocalPaths), ReferenceCopyLocalPaths.DestinationSubDirectory = %(_ReferenceCopyLocalPaths.DestinationSubDirectory) Filename = %(_ReferenceCopyLocalPaths.Filename) Extension = %(_ReferenceCopyLocalPaths.Extension)" Importance="High" Condition="'@(_ReferenceCopyLocalPaths)' != ''" /><ItemGroup><!-- Add file to package with consideration of sub folder. If empty, the root folder is chosen. --><BuildOutputInPackage Include="@(_ReferenceCopyLocalPaths)" TargetPath="%(_ReferenceCopyLocalPaths.DestinationSubDirectory)"/></ItemGroup></Target></Project>

When I try to pack the LookupListCache project I got the LookupListCache.9.0.0-pg-03.nupkg file, and in it's lib folder inside it has the 3 referenced .dll files:generated filesIn the .LookupListCache.nuspec file I have:

<?xml version="1.0" encoding="utf-8"?><package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"><metadata><id>LookupListCache</id><version>9.0.0-pg-03</version><title>LookupListCache</title><authors>Yulian Dimitrov</authors><description>This package contains everything for setting up a LookupListCache. Please configure LookupListCache connection string.</description><releaseNotes>Some release notes</releaseNotes><repository type="git" commit="5f74f5b8b658ff9995b648a3c09e5bd09b263515" /><dependencies><group targetFramework="net8.0"><dependency id="AutoMapper" version="13.0.1" exclude="Build,Analyzers" /><dependency id="EFCore.NamingConventions" version="8.0.3" exclude="Build,Analyzers" /><dependency id="FluentValidation.AspNetCore" version="11.3.0" exclude="Build,Analyzers" /><dependency id="Hangfire.Core" version="1.8.6" exclude="Build,Analyzers" /><dependency id="LEXolutionServiceBus" version="1.5.175.63106" exclude="Build,Analyzers" /><dependency id="Microsoft.EntityFrameworkCore" version="8.0.8" exclude="Build,Analyzers" /><dependency id="Microsoft.Extensions.Configuration" version="8.0.0" exclude="Build,Analyzers" /><dependency id="Microsoft.Extensions.Configuration.Abstractions" version="8.0.0" exclude="Build,Analyzers" /><dependency id="Microsoft.Extensions.Configuration.EnvironmentVariables" version="8.0.0" exclude="Build,Analyzers" /><dependency id="Microsoft.Extensions.Configuration.FileExtensions" version="8.0.0" exclude="Build,Analyzers" /><dependency id="Microsoft.Extensions.Configuration.Json" version="8.0.0" exclude="Build,Analyzers" /><dependency id="Newtonsoft.Json" version="13.0.3" exclude="Build,Analyzers" /><dependency id="Npgsql.EntityFrameworkCore.PostgreSQL" version="8.0.8" exclude="Build,Analyzers" /></group></dependencies></metadata></package>

And when I try to install this package in other solution it says that it cant find the nuget packages:

NU1101: Unable to find package LookupListCache.Common. No packages exist with this id in source(s): C:\Program Files\dotnet\library-packs, Local, Microsoft Visual Studio Offline Packages, nuget.org, standard_pdeNU1101: Unable to find package LookupListCache.Migrations.CamelCase. No packages exist with this id in source(s): C:\Program Files\dotnet\library-packs, Local, Microsoft Visual Studio Offline Packages, nuget.org, standard_pdeNU1101: Unable to find package LookupListCache.Migrations.SnakeCase. No packages exist with this id in source(s): C:\Program Files\dotnet\library-packs, Local, Microsoft Visual Studio Offline Packages, nuget.org, standard_pde

Is there a way that I can pack this project without the need to create separate nuget packages for the rest of the referenced projects?

How to handle class name collision in nuget package

$
0
0

I have a C# project with a static class MyNamespace.Global. It contains things like constants that are used throughout the code. e.g. Global.MAX_NAME_LENGTH. One of the 3rd party nuget packages I'm using declares a class Global without a namespace. When I try to build my project, I get a bunch of errors saying Global does not contain MAX_NAME_LENGTH. It's trying to use the 3rd party Global class instead of my class, even though I have "using MyNamespace" at the top of my source files. Is there a way to get around this without changing all of my calls to MyNamespace.Global or renaming my Global class?

how to specify location of nuget packages when package restore is enabled?

$
0
0

I am working on a .net solution and use nuget for my package management. I have selected the option to "Enable Nuget Package Restore" so that the nuget packages not checked in to source control.

Prior to this I had a nuget.config file at the same level as the solution where I included to following enabling me to specify the location of the nuget packages.

<settings> <repositoryPath>..\Build\NuGetPackages\</repositoryPath> </settings> 

Since I enabled the nuget package restore, this is no longer working. I tried to update the config file within the .nuget generated folder but that does not work either.

So where I am going wrong and how can I specify the location of the packages folder?


Package source mapping does not work since 17.5.0

$
0
0

I have recently had the problem that all my projects have difficulties with the Nuget packages. Since they seem to be equipped with additional security since version 17.5, I have to reconfigure them. Unfortunately, this does not work.As an example with the Nuget package: Microsoft.EntityFrameworkCore

Does anyone have an idea how I can solve this?

https://learn.microsoft.com/de-de/nuget/consume-packages/package-source-mappingAs with Microsoft's documentation on this page, I am supposed to follow the steps. I have done that. Unfortunately, it doesn't work at all. VS does not respond to the package source mapping at all. I have VS 2022 Preview Version 17.7.0.

I've been trying to install the nuget packages manually for days, and that doesn't work either. VS does not find them.

Error NU1605: Package downgrade when updating Azure.Identity in SDK-style .NET Framework project using Central Package Management

$
0
0

I’ve migrated some legacy .NET Framework projects to SDK-style projects and switched to using Central Package Management. When I try to update the Azure.Identity package to version 1.12.0, I get the following error in Visual Studio:

Warning As Error: Detected package downgrade: Microsoft.Identity.Client.Extensions.Msal from 4.61.3 to 4.57.0.Reference the package directly from the project to select a different version. APIFunctionalTests -> Azure.Identity 1.12.0 -> Microsoft.Identity.Client.Extensions.Msal (>= 4.61.3) APIFunctionalTests -> Microsoft.Identity.Client.Extensions.Msal (>= 4.57.0)

I understand that Azure.Identity requires Microsoft.Identity.Client.Extensions.Msal (>= 4.61.3), but my project seems to be referencing version 4.57.0. Since I’m using Central Package Management, there are no csproj files to manually edit. I was under the impression that installing Azure.Identity 1.12.0 should automatically update Microsoft.Identity.Client.Extensions.Msal to version 4.61.3 in my Directory.Packages.props file, but this is not happening.

Here are the steps I’ve tried so far:

  • Directly referencing Microsoft.Identity.Client.Extensions.Msal in thecentral package file (Directory.Packages.props) with version 4.57.0.

What else can I do to resolve this package downgrade error?

Set NuGet package versions of runtime components, to prevent vulnerable dependencies?

$
0
0

In order to prevent vulnerable, transitive dependencies, I added guard versions to the Directory.Packages.props file, used for Central Package Management (CPM) in Visual Studio 2022. Transitive pinning is enabled, of course:

<ItemGroup><!-- Minimum versions everywhere, preventing vulnerable dependencies --><!-- CVE-2024-32655 in <=6.0.10/8.0.2; can be removed when >=6.0.11/8.0.3 in all dependencies. --><PackageVersion Include="Npgsql" Version="8.0.3" /><!-- now also vulnerable, => 8.0.1, but not actual part of the .NET runtime. --><!-- Name is misleading! --><PackageVersion Include="System.Runtime.Caching" Version="8.0.0" /><!--CVE-2024-30105 --><!-- Part of .NET runtime since NET 8, 8.0.4 now also vulnerable. --><PackageVersion Include="System.Text.Json" Version="8.0.4" /></ItemGroup>

Now, the System.Text.Json package version 8.0.4 has got another vulnerability and should be updated to 8.0.5.

I also noticed that System.Text.Json is now part of the .NET runtime (I think since .NET 8 Edit: No, already NET Core 3.x).

  1. Specifying a PackageVersion no longer makes the build deliver a System.Text.Json.dll, so is the version now ignored?

  2. I get a warning, both in Visual Studio and in later vulnerability scans, when I specify the package with version 8.0.4. But as I see, under .NET 8, it solely depends on the runtime version, so I suppose the warning is just in case that older .NET versions are used (which aren't). Correct?

  3. After removing the PackageVersion, the vulnerable version 8.0.4 still appears as a dependency of a 3rd party component, but without warning. Is this due to an outdated runtime on my DEV machine, and no issue if the application runs under an up-to-date runtime?

  4. And a last question: If it's best to not set PackageVersion for runtime components, how can I quickly find out which components have moved to the runtime, which weren't there in NET 5 and 6?

FileNotFoundException: Could not load file or assembly "System.Runtime version=8.0.0.0"

$
0
0

I have been working on a .NET 8 project in Visual Studio for months. Everything was working well until one day out of nowhere, without changing anything in the code/OS/VS the project started throwing this exception whenever I try to run it:

Could not load file or assembly "System.Runtime version=8.0.0.0"

Here's what I've tried and hasn't worked:

  • Reinstalling Visual Studio
  • Reinstalling .NET
  • Repairing .NET
  • Restoring NuGet packages
  • Deleting bin and obj folders from my project, cleaning and rebuilding the solution
  • Cloning the repository again
  • Manually reinstalled NuGet packages/dependencies
  • Deleting NuGet cache
  • Manually installed System.Runtime via NuGet (it wasn't previously installed but it used to work just fine)

Curiously enough, when I try to run the project in Rider instead of VS on a different machine, the project runs just fine. I have seen many people encounter this error online but none of their approaches worked for me.

The .sln has only one project whose .NET version is 8.

Unable to update Nuget package microsoft.identity.serviceessentials.aspnetcore to ver 1.28.1

$
0
0

I'm updating the nuget package microsoft.identity.serviceessentials.aspnetcore 1.26.0 tover 1.28.1. however I get the below error message in Package Manager Console.

Unable to find package Microsoft.Identity.ServerAuthorization. No packages exist with this id in source(s)

Looks like the dependent package Microsoft.Identity.ServerAuthorization is not available in the feed and I'm unable to find it to download from anywhere and publish to the feed.

Please help to resolve this issue or guide me to find the package in the internet.

Thanks in advance.

~Sreeni

Could not load file or assembly 'System.Web.Http, Version=5.0.0.0

$
0
0

After installing Microsoft.Aspnet.Webapi.Webhost package to my web api project, I end up with the following exception:

Could not load file or assembly 'System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Publish legacy symbol nuget packages

$
0
0

I have an empty legacy SDK C# class library project (with new Class1 class and single empty method inside him) and I want to publish it with symbols. I did this in the past for SDK project, but it looks like a sourcelink is not supported for legacy .net 4.5.2 .NET Framework projects (despite SymbolPackageFormat=>snupkg configuration in the project file, the produced package is in .symbols.nupkg format).

So, my steps are:

1. nuget pack -Build -Symbols -OutputDirectory "..\artifacts" -Version 1.0.0

created 2 packages: PackageName.Version.nupkg and PackageName.Version.symbols.nupkg

2. nuget push PackageName.Version.symbols.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey ###

The package has been successfully published with .pdb files. There are PackageName.dll and PackageName.pdb in the lib folder inside the package storage folder (inside packages) and in the bin folder in the project itself. But when I try to debug the package library after consuming, I see the error:

*Source Not found*   Class1.cs not found   You need to find Class1.cs to view the source for the current stack frame.

Also, even if I fix it, does it mean that during consuming I have to decide which package should I consume, either: normal .nupkg or symbols.nupkg (assuming that I also need to publish both of them too with different name, like PackageName vs PackageName.WithSymbols)?


Creating a NuGet package containing a .NET class library to copy sass files to a .NET consumer project and allow those files to be used and edited

$
0
0

I am attempting to create a NuGet package to copy sass files to a consumer project. I am able to see the files inside the consumer project (like in the image below) But they are locked and the file paths still reference the NuGet package project on my local machine.

Files from NuGet package

The NuGet project is not published it is just packed to a folder on my local which is referenced in the consumer project to install/update.

Here are my project files for the NuGet package:

I suspect the .targets file is not working correctly as I don't see the message that is in there when building or installing. It seems the reference to the files in the consumer project just comes from the line in the .nuspec that sets the target to "contentFiles\any\any\Theming".

.csproj file:

<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>net8.0</TargetFramework><GeneratePackageOnBuild>true</GeneratePackageOnBuild><PackageId>Theming</PackageId><Version>1.1.5</Version><Authors>author</Authors><Description>theming</Description><PackageTags>sass scss copy</PackageTags><NuspecFile>Theming.nuspec</NuspecFile></PropertyGroup><ItemGroup><None Update="sass\**\*.scss"><Pack>true</Pack><PackagePath>Sass\</PackagePath></None><None Update="build\Theming.targets"><Pack>true</Pack><PackagePath>build\</PackagePath></None></ItemGroup></Project>

.nuspec file:

<?xml version="1.0"?><package><metadata><id>Theming</id><version>1.1.5</version><authors>author</authors><owners>owner</owners><requireLicenseAcceptance>false</requireLicenseAcceptance><description>Theming</description><contentFiles><files include="Sass\**\*.scss" buildAction="None" copyToOutput="true" flatten="true" /></contentFiles></metadata><files><file src="Sass\**\*.scss" target="contentFiles\any\any\Theming" /><file src="build\Theming.targets" target="build\Theming.targets" /></files></package>

.targets file:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><Target Name="Theming" AfterTargets="Build"><Message Text="Copying SASS files to $(MSBuildProjectDirectory)\Theming" Importance="High" /><ItemGroup><SassFiles Include="$(MSBuildThisFileDirectory)Sass\**\*.scss" /></ItemGroup><Copy SourceFiles="@(SassFiles)" DestinationFolder="$(MSBuildProjectDirectory)\Theming" /></Target></Project>

If I try to explicitly include the files in the consumer project it cannot find them:

<ItemGroup><None Include="Theming\_theming.scss"><CopyToOutputDirectory>Always</CopyToOutputDirectory></None><None Include="Theming\_generic-names.scss"><CopyToOutputDirectory>Always</CopyToOutputDirectory></None><None Include="Theming\_default-variables.scss"><CopyToOutputDirectory>Always</CopyToOutputDirectory></None></ItemGroup>

Result of the above:

files after include

Multi-Framework Targeting for NuGet Packages

$
0
0

Background - My Build Scripting

I would like to use the dotnet CLI to create a nuget package that can target the following frameworks: net462, net48, net8.0. My library has no dependencies (i.e. it doesn't require any other NuGet packages or projects).

I have written a powershell build script that builds my library such that three DLLs are created. The relevant part of the build script is included below:

dotnet build TestCI.sln -c "net462" -f "net462" -p:Platform=x64 -p:Version=$($MAJOR_MINOR_PATCH) --no-restore --disable-build-serversdotnet build TestCI.sln -c "net48"  -f "net48"  -p:Platform=x64 -p:Version=$($MAJOR_MINOR_PATCH) --no-restore --disable-build-serversdotnet build TestCI.sln -c "net8.0" -f "net8.0" -p:Platform=x64 -p:Version=$($MAJOR_MINOR_PATCH) --no-restore --disable-build-servers

This results in the following folder structure:

bin|-- net8.0-x64|-- |-- TestCI.dll|-- net48-x64|-- |-- TestCI.dll|-- net462-x64|-- |-- TestCI.dll

When decompiled with DotPeek, I can see that each DLL contains:

  1. The information from my .csproj that I would like/expect to see
  2. The proper target framework versions and runtime identifiers

So far, so good.

The Goal - A NuGet Package for Multiple Framework Targets

I would like to package these three DLLs into a single nuget package that can be deployed to net462, net48, and net8.0 runtimes, using only my SDK-style .csproj file and the CLI.

The Problem - Versioning Upon Packaging

My long-term goal is to automate the building and packaging of this library (and others) using GitHub actions - hence the scripting. However, ehcin I run the following dotnet pack command:

dotnet pack TestCI\TestCI.csproj -p:PackageVersion=$($MAJOR_MINOR_PATCH) --no-restore --no-build

The resulting NuGet package contains DLLs that all specify net8.0 as the target framework. The f

TestCI.nupkg|-- lib|-- |-- net462|-- |-- |-- TestCI.dll|-- |-- net48|-- |-- |-- TestCI.dll|-- |-- net8.0|-- |-- |-- TestCI.dll

However when inspecting each DLL, they all contain the following line, regardless of the lib subdirecotry:

[assembly: TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]

I.e. there doesn't appear to be a difference between the DLLs packged despite the fact that I know that each DLL was built to a different target framework, and have confirmed this on each DLL in the bin directory.

So Far, I've Tried...

So far, I've tried several variations of the dotnet pack command, even including a rudimentary nuspec file:

dotnet pack TestCI\TestCI.csproj -p:PackageVersion=$($MAJOR_MINOR_PATCH) -p:NuspecFile=.nuspec --no-restore --no-build

(see this post on multi-targeted nuget packages)

This works, however I don't like this soltuion for the following reasons:

  1. The package version isn't properly applied to this package (results in 0.0.0), and I require the ability to control versioning information for CICD purposes.
  2. I would prefer to keep everything contained in my SDK-style .csproj file to keep my repository cleaner and simpler.

I've also ensured that my .csproj file contains the following element:

<TargetFrameworks>net462;net48;net8.0</TargetFrameworks>    

The Asks

  1. Am I misunderstanding how .NET works? Am I needlessly complicating my workflow?
  2. Has anyone encountered a similar situation?
  3. Do I need to use a .nuspec file?
  4. Is it possible to achive what I've described with only a SDK .csproj file and the CLI?

Edits

[2024-07-26]

  • I am using JetBrains DotPeek to inspect the NuGet package
  • The csproj file I am using is included below:
<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><RootNamespace>TestCI</RootNamespace><Company>XYZ</Company><Copyright>XYZ (c) 2024</Copyright><Version>0.0.1</Version></PropertyGroup><PropertyGroup><TargetFrameworks>net462;net48;net8.0-windows</TargetFrameworks>        <Configurations>net48;net462;net8.0-windows</Configurations><Platforms>x64</Platforms><PlatformTarget>x64</PlatformTarget><OutputPath>bin\$(Configuration)-$(Platform)\</OutputPath></PropertyGroup><PropertyGroup><ProductName>$(RootNamesapce)</ProductName><OutputType>Library</OutputType><IsTestProject>False</IsTestProject></PropertyGroup><PropertyGroup><PackageID>$(RootNamespace)</PackageID><PackageVersion>$(Version)</PackageVersion><IsPackable>True</IsPackable><IncludeBuildOutput>True</IncludeBuildOutput><GeneratePackageOnBuild>False</GeneratePackageOnBuild><PackageOutputPath>..\nupkg</PackageOutputPath><PackageDescription>XYZ</PackageDescription><RepositoryUrl>XYZ</RepositoryUrl></PropertyGroup><PropertyGroup><DefineConstants>TRACE;DEBUG</DefineConstants><DebugType>embedded</DebugType><OutDir>bin\$(Configuration)-$(Platform)</OutDir></PropertyGroup><PropertyGroup><GenerateAssemblyInfo>True</GenerateAssemblyInfo><AssemblyName>$(RootNamespace)</AssemblyName><AssemblyVersion>$(Version).0</AssemblyVersion><FileVersion>$(Version).0</FileVersion></PropertyGroup><ItemGroup><Compile Remove=".github\**" /><EmbeddedResource Remove=".github\**" /><None Remove=".github\**" /></ItemGroup></Project>

Is it possible to use Source link in private on-prem Gitlab instance?

$
0
0

I'm trying to create and push a simple .net library and want to be able to debug it using source link but from the docs is not clear if the source link works only for public repos (like github and gitlab, for example) or if it works as well for on-prem Gitlab instance.

I've tried to use it with .NET8 with s csproj like this:

<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net8.0</TargetFramework><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable><PublishRepositoryUrl>true</PublishRepositoryUrl><IncludeSymbols>true</IncludeSymbols><SymbolPackageFormat>snupkg</SymbolPackageFormat><EmbedUntrackedSources>true</EmbedUntrackedSources><SourceLinkCreate>true</SourceLinkCreate></PropertyGroup><ItemGroup><!-- compile time only dependency to make sourcelink work in gitlab --><PackageReference Include="Microsoft.SourceLink.GitLab" Version="8.0.0"><PrivateAssets>all</PrivateAssets><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets></PackageReference></ItemGroup></Project>

When I try to debug (as in, step into the code) what Visual Studio gives me is this message:enter image description here

And in the SymbolCache folder I have this:enter image description here

This tells me that what is happening is a decompilation process and source-link debug is not working.

In the publish nupkg I can see the repo info, so it seems that at least the repo linking is happening, not sure why I'm not able to do the source-link debugging.enter image description here

Can you help me understand this process?

How can I clear the NuGet package cache using the command line?

$
0
0

I can clear my development computer's NuGet package cache using Visual Studio menu ToolsOptionsNuGet Package ManagerGeneral: Clear Package Cache button.

I would like to do this on the command line. Unfortunately, I can not find a related command line switch for nuget.exe.

Did I miss something?

"Could not find part of path to System.Runtime.CompilerServices.Unsafe.dll" when installing nuget packages

$
0
0

I'm attempting to install some nuget packages into my project and keep getting an error that looks like this:

Could not find a part of the path 'C:\<path to my project>\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll'

I have tried installing the nuget package for System.Runtime.CompilerServices.Unsafe but that gave me the same issue.

I also tried downloading System.Runtime.CompilerServices.Unsafe directly from the nuget website and using gacutil on it but that did not change anything.

Own Nuget Server - The V2 feed at '' returned an unexpected status code '404 Not Found'

$
0
0

I created my own Nuget Server following the documentation and I got it, but I cannot access the packages from Visual Studio 2019 Community Nuget Package Manager.

So, when I do it through a browser I get this, which seems fine:enter image description here

When I click on "here" to view the packages I see the test one I added, and if I click it I can even download it:

enter image description here

However, when I access by Visual Studio I get this:

enter image description here

The full error says:

[Nuget Server] The V2 feed at'http://mywebsite.com/NugetServer/Packages/Search()?$filter=IsLatestVersion&searchTerm=''&targetFramework=''&includePrerelease=false&$skip=0&$top=26&semVerLevel=2.0.0' returned an unexpected status code '404 Not Found'. But I can't figure out why.

This is how I added it to the Nuget Manager:

enter image description here

This is the folder structure of the site:enter image description hereenter image description here

As you can see the package test.1.0.0.nupkg is where the NugetServer project told me to put it.

I tried several things:

  • Giving Everyone FullControl of the folder (because at the beginning I got 403 Forbiden instead of 404)

  • Changing the folder structure, puting the nupkg package inside a folder named nuget, put the whole Packages folder inside the nuget folder and other things I saw as solutions in other Stackoverflow threads.

  • Transforming everything to VB as this Stackoverflow thread suggested.

  • Changing IIS parameters

Nothing worked for me, so I need a bit of help to find the way.

Maybe I need something for the "Search()" to work? I'm lost.

If you need more info I can provide, just ask, please.

ModuleInitializeException on Azure Deployment: Missing Dependencies for Microsoft.Identity.Web.Certificate Version 1.25.3

$
0
0

I'm using

<PackageReference Include="Microsoft.Identity.Web.Certificate" Version="1.25.3" />

in my project. The application runs successfully on my local machine. However, when deployed to any environment in Azure, I encounter a ModuleInitializeException error. This error message states that "Azure.Identity" cannot be loaded for the module C:\home\site\platform\app_data\modules\TestModule.Web.dll.Application Event Logs -> ErrorPackageReference

Upon investigation, I found that the following libraries are missing in the Azure environment, causing the issue:

  • Azure.Security.KeyVault.Secrets.dll
  • Microsoft.Identity.Client.Extensions.Msal.dll
  • Azure.Identity.dll

These libraries appear to be related to the Microsoft.Identity.Web.Certificate package. I have tried upgrading and downgrading the package version, but the issue persists.

Any suggestions for resolving this error?Missing Libraries


Address Standardization and Parsing in .Net Core [closed]

ModuleInitializeException on Azure Deployment: Missing Dependencies for Microsoft.Identity.Web.Certificate Version 1.25.3

$
0
0

I'm using PackageReference Include="Microsoft.Identity.Web.Certificate" Version="1.25.3" in my project. The application runs successfully on my local machine. However, when deployed to any environment in Azure, I encounter a ModuleInitializeException error. This error message states that "Azure.Identity" cannot be loaded for the module C:\home\site\platform\app_data\modules\TestModule.Web.dll.

PackageReferenceApplication Event Logs -\> Error

Upon investigation, I found that the following libraries are missing in the Azure environment, causing the issue:

  • Azure.Security.KeyVault.Secrets.dll
  • Microsoft.Identity.Client.Extensions.Msal.dll
  • Azure.Identity.dll

These libraries appear to be related to the Microsoft.Identity.Web.Certificate package. I have tried upgrading and downgrading the package version, but the issue persists. Any suggestions for resolving this error?

Missing Libraries

Obfuscate a nuget package with Obfuscar

$
0
0

I have a class library project that needs to become a nuget package. I managed to obfuscate the dll, but how do I obfuscate the package I need to publish?

I have used "$(Obfuscar)" obfuscar.xml in thge post-buld event, but i have no clue how to proceed

Overriding Remote Repository in Premake5 script running

$
0
0

I have a C++ project on Visual Studio 2022 that when trying to setup, I'm unable of running the premake5 script with vs2022 parameter on cmd.

I have a custom package that resides in my local system.when Running the premake5, it searches for the remote packages in https://api.nuget.org/v3/index.json and it's failing because my package does not exist there.Therefore, I'm asking what the is way/syntax to override in premake5.lua the remote repository or to make the script to search for packages in my local system also for example ( C:/NuGetPackages ) .

C:\Users>./premake5.exe vs2022Found Sysroot of /Building configurations...Running action 'vs2022'...Examining NuGet package source 'https://api.nuget.org/v3/index.json'...Examining NuGet package 'Project.Custom'...Error: ** Error: NuGet package 'Project.Custom' for project 'Project' couldn't be found in the repository

Tried to search the documentation of premake, didn't find how to get that.What i'm looking for is to make the script also search for packages in my custom directory (locally)

Visual Studio Code using wrong NuGet package when building

$
0
0

I am trying build a .NET app in Visual Studio Code (VS Code) and am getting this error:

Logic.csproj : error NU1301: Unable to load the service index for source https://pkgs.dev.azure.com/XXXX/_packaging/XXXnuget/nuget/v3/index.json. [C:\Logic.sln]

Where XXX is a previous client's NuGet package I want to ignore.

Trying dotnet nuget locals --clear all in the PowerShell terminal has no effect. Doing it on the command line does do something, but I still get a build failure in VS Code.

The only way I found to disable the NuGet package was to go to Visual Studio 2022 and turn off/uncheck the package in Tools -> Options -> Package Sources in an empty Visual Studio environment (no solution or project) and then go back and build in VS Code.

Is there a way to remove package sources in VS Code? How can I resolve the issue?

NuGet packages suddenly disappeared in my .NET MAUI project

$
0
0

I am using Visual Studio Community 2022. I have three .NET MAUI projects in this solution, all of which were working as expected with the required NuGet packages showing up in NuGet Package Manager.

Suddenly, I started to get errors that assemblies were missing (CommunityToolkit.Maui, CommunityToolit.Mvvm, etc.). Upon checking "Manage NuGet Packages", they were all gone.

  • I have verified that in the project.csproj all of the Package References are there.
  • I have verified the proper environment variables.
  • The other projects still work.
  • I have this project on a separate, older computer and it works. I have compared every aspect of the two that I could think of and cannot find a cause for this behaviour.
  • I cannot install the needed NuGet packages to this project.
  • I cannot restore NuGet packages in the PM console.
  • I have restarted the computer.
  • I have repaired Visual Studio.
  • I have deleted the obj/bin folders.
  • I expected to have the NuGet packages available to my project and for my project work work as it was previously.

How to add a Feed to NuGet in Visual Studio [closed]

$
0
0

My boss sent this today:

Adjust your nuget to the following feed:https://.....azure.....artifacts....nuget....index.json

Does anyone have any idea where I go to solve this thing?

I tried to put it here at this stop, but I don't know if that's correct:

enter image description here


How to build nuget package from nuspec without platform version?

$
0
0

I am trying to build a nuget package only for dependencies consisting of 3rd party packages. If I'd be starting from scratch probably adn empty project with reguired assemblies might be a better idea but I already have nuspec files available so I don't want to create my own projects for future safty. Here is one such nuspec file:

<?xml version="1.0" encoding="utf-8"?><package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"><metadata><id>MyCompany.TestPack</id><tags>Test</tags><version>1.0.0</version><authors>Example Inc.</authors><owners>Example Inc.</owners><description>This package provides data.</description><language>en-US</language><licenseUrl>https://example.com</licenseUrl><requireLicenseAcceptance>true</requireLicenseAcceptance><dependencies><group targetFramework="net6.0-windows"><dependency id="DevExpress.Data" version="[22.2.9]" /></group></dependencies><frameworkReferences /><developmentDependency>false</developmentDependency></metadata></package>

And here is the nuget command to build package:

nuget pack my.package.nuspec

Problem is it fails with error:

NU1012: Some dependency group TFMs are missing a platform version:net6.0-windows

I also tried /p:WindowsTargetPlatformVersion=7 with nuget command without success.
But if I change targetFramework="net6.0-windows" to "net6.0-windows7.0" or 10 etc., it works.
My question is, how can I build package from above nuspec with out providing platform version? or if it is necesssary then how can I set it through nuget command?