with the release of the .net core i have been trying to build a simple project, however whenever i try and add a dll reference in my project i get the following message
".Net Core Projects only support Referencing .Net Framework assemblies in this release To Reference other assemblies they need to be included in nuget package and reference that package"
i was getting this message in RC2 but not in RC1, is anyone else having this issue and does anyone know how to resolve it? i have not been able to find anything relating to this other than a git issue ticket https://github.com/aspnet/Home/issues/1612
For referencing external dll in .net core you need to create you own nuget package.
The NuGet docs show how to create a package from a dll:https://docs.nuget.org/create/hosting-your-own-nuget-feeds . You can put that nuget package in a local folder and use that as a feed: [https://docs.nuget.org/create/hosting-your-own-nuget-feeds]
For this you need to edit the nuspec file and add the following code in the nuspec file.
<package>
*******--Some code--*****
<metadata>
<references>
<reference file="xxx.dll"/>
</references>
</metadata>
<--For addig reference of external dll-->
<files>
<file src="path\*.dll" target="lib\netCoreApp1.0"/>
</files>
Now create .nupkg file and install this package in your project.
Hope this solution works for you.
Related
I have a few projects, which could be a console application, Web Application, WebAPI, MVC etc) and a normal Class Library (not Core/.Net 6) which contains Newtonsoft.Json dll (latest version).
Each of the applications have their own version of Newtonsoft.Json dll that has been added manually for that project. In doing this it means an older app could have used version 1.0 the next application could have used v 2.0 and later apps could have used a much later version etc
I would like to share this class library through a Nuget package but i have added the latest version of Newtonsoft.Json dll into my own class library.
When i create a .nuspec file i would like to exclude this file but using this code
<files>
<file src="bin\Release\Newtonsoft.dll" target="\" />
</files>
within the .nuspec file doesnt seem to work, reading https://learn.microsoft.com/en-us/nuget/reference/nuspec suggests to use the exclude but i cant get the syntax right.
What am i missing here?
In your nuspec include this:
<dependencies>
<dependency id="Newtonsoft.Json" version="[3.5,14)" />
</dependencies>
Where 3.5 is the oldest version you support and 14 is the newest you do not support.
Then you can leave out newtonsoft.dll from you own package and the project you install the nuget into will be able to determine which newtonsoft to use.
I want to create a NuGet package from a class library targeting .Net Framework 4.5 (not 4.5.1, or 4.5.2) which contains source code files, and I have trouble finding how.
The reason being that I would like to be able to debug it. I already created the symbols package, and it seems to works, provided I open the *.cs file I want to debug when VS2022 asks me for it.
To pack, I use a standard nuspec file, to which I specified the files I want to add taking inspiration from here
<contentFiles>
<files include="**\*.cs" buildAction="content" flatten="true" copyToOutput="true"/>
</contentFiles>
</metadata>
<files>
<file src="**\*.cs" target="src" />
</files>
All the files are sent to the .nupkg in a src folder, as expected.
The command I use to pack is
nuget pack *.csproj -Symbols -SymbolPackageFormat snupkg
I spent all day trying to figure out how to include source so that VS can find the source files after I install the package, to no avail. Any feedback would be appreciated.
Is there a way for this to be streamlined, or is uploading the file you want to debug the only option for 4.5?
Thanks!
As we can see that contentFiles is used for PackageReference form this link.
And .NET Framework projects support PackageReference, but currently default to packages.config.
I'm not sure which format your project is using. If you are using package.config you can try to Migrate from packages.config to PackageReference and try again.
I created a .NET framework class library targeting 4.6.1 .NET Framework. The project contains one .cs class and no external references to any libraries, DLLs, or NuGet packages. Here is the nuspec:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<!-- Required elements-->
<id>MyEventLogger.Core</id>
<version>1.0.0</version>
<description>Logs event log</description>
<authors>Me</authors>
</metadata>
<files>
<file src="MyEventLogger.Core\**\bin\Debug\*.dll" target="lib\net" />
<file src="MyEventLogger.Core\**\bin\Debug\*.dll" target="lib\netstandard" />
</files>
</package>
I am having trouble importing this from an ASP.NET Core application running .NET Framework 4.7.1.
The error I get is that the package does not support any frameworks:
I am using Azure Devops Build pipeline to initiate the pack and push to a local feed. How should I reference this correctly so that an application on a newer version of .NET Framework can still use this library that is on an older version?
Thank you for any help! I can't find how to fix this error anywhere or good examples of targeting multiple .NET Frameworks.
I got it working when I was able to use the following file nodes:
<files>
<file src="**\MyEventLogger.Core.dll" target="lib\net461\MyEventLogger.Core.dll" />
</files>
What helped me figure this out was to install NuGet onto my machine as well as installing the NuGetPackageExplorer. You can create a package using the NuGetPackageExplorer and then exporting the .nuspec file. I copied that .nuspec file into my repository and then pointed my Azure DevOps build pipeline to the .nuspec file. This error disappears when I import the package into another project.
For you to be able to use code across .net framework and .net core, you need to write your code in a library written in .net standard. You may find a similar solution here
Thank you
I'm trying to figure out how to migrate a project from PCL to .netstandard 1.2.
I have a solution where I have a PCL project (portable45-net45+win8+wpa81) and a .Net Standard (netstandard1.2) project which has all it files linked into the PCL project.
Currently we create a nuget package from the PCL project using a nuspec file.
Now what would be the best approach to have both available in 1 nuget package?
I find the use of nuget pack vs dotnet pack and mixing multiple frameworks and project types (csproj) very confusing.
Also appearantly there is a new csproj format for VS2017+ projects, should I convert the PCL project?
Eventually the nuget should only contain the .netstandard1.2 project but we want to take both up the dependency tree during migration.
what would be the best approach to have both available in 1 nuget package?
You can still use .nuspec file to accomplish this, just need include the dll files from PCL project and .Net Standard project into different frameworks.
Following is my test .nuspec file, you can check it for details:
<?xml version="1.0"?>
<package >
<metadata>
<id>My.Package</id>
<version>1.0.0</version>
<authors>Tester</authors>
<owners>Tester</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package description</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2018</copyright>
<tags>Tag1 Tag2</tags>
</metadata>
<files>
<file src="TestPCL\bin\Debug\TestPCL.dll" target="lib\portable-net45+wp8\" />
<file src="TestStandard\bin\Debug\netstandard1.2\TestStandard.dll" target="lib\netstandard1.2\" />
</files>
</package>
When you install this package to the PCL project and .Net Standard project, nuget will select the DLL file under the corresponding framework to your project.
I have a REST Api implemented using Durable Function App in Azure, which uses netstandard2.0, and I have other class libraries in this solution also using netstandard2.0. One of them is contracts projects.
There is another solution where the UAT tests placed for this solution. The reason for this is that Specflow is still not available for .Net Core, it is available for .Net Framework only. Being able to test the Api I need the contracts for the Api. That is the reason I need to include the REST Api solution Contracts project (this one is netstandard2.0). This dependency is managed by nuget.
When I would like to install the Contracts package (using netstandard2.0) in Specflow project (which uses .Net Framework 4.7.1) I get the error below.
What I tried:
I restarted Visual Studio a few times because I experienced that sometimes it gets crazy when .Net Core or .Net Standard projects are in use. Restarting did not help.
I opened the project from JetBrains Rider, but it did not see the netstandard2.0 nuget package in the repository. I believe it is due to that the project uses .Net Framework 4.7.1 and not Net Standard 2.0
I saw the error Cannot create "C:\...\REST.Api.dll" because a file or directory with the same name already exists.. So, I deleted all packages under the solution packages directory. I also deleted cache in Visual Studio. But, the next time I started Visual Studio and tried to install package the same error occurred again.
I also tried to install package using console on my machine (nuget.exe install ...). The error is the same.
How it is possible to resolve this issue? I read that from .Net Framework 4.6 and above and .Net Core it is possible to reference .Net Standard libraries.
Attempting to gather dependency information for package 'REST.Api.1.0.0-20180305-154726' with respect to project 'MasterData.Features.HttpClient', targeting '.NETFramework,Version=v4.7.1'
Gathering dependency information took 861.8 ms
Attempting to resolve dependencies for package 'REST.Api.1.0.0-20180305-154726' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'REST.Api.1.0.0-20180305-154726'
Resolved actions to install package 'REST.Api.1.0.0-20180305-154726'
GET https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg
Retrieving package 'REST.Api 1.0.0-20180305-154726' from 'Sayusi Ando's Digital Library Packages'.
OK https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg 2343ms
Installing REST.Api 1.0.0-20180305-154726.
Error downloading 'REST.Api.1.0.0-20180305-154726' from 'https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg'.
Cannot create "C:\Users\username\.nuget\packages\REST.api\1.0.0-20180305-154726\lib\netstandard2.0\REST.Api.dll" because a file or directory with the same name already exists.
GET https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg
OK https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg 462ms
Installing REST.Api 1.0.0-20180305-154726.
Error downloading 'REST.Api.1.0.0-20180305-154726' from 'https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg'.
Cannot create "C:\Users\username\.nuget\packages\REST.api\1.0.0-20180305-154726\lib\netstandard2.0\REST.Api.dll" because a file or directory with the same name already exists.
GET https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg
OK https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg 464ms
Installing REST.Api 1.0.0-20180305-154726.
Install failed. Rolling back...
Package 'REST.Api.1.0.0-20180305-154726' does not exist in project 'MasterData.Features.HttpClient'
Package 'REST.Api.1.0.0-20180305-154726' does not exist in folder 'C:\VSTS\REST.QA.Features\src\packages'
Executing nuget actions took 3.51 sec
Error downloading 'REST.Api.1.0.0-20180305-154726' from 'https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg'.
Cannot create "C:\Users\username\.nuget\packages\REST.api\1.0.0-20180305-154726\lib\netstandard2.0\REST.Api.dll" because a file or directory with the same name already exists.
Time Elapsed: 00:00:05.5462783
The root of the problem is that the target properties conflicted with another filename. (names are shortened)
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<!-- package stuff -->
<dependencies>
<group targetFramework=".NETStandard2.0" />
</dependencies>
</metadata>
<files>
<file src="..." target="lib\netstandard2.0\Contracts.dll" />
<file src="..." target="lib\netstandard2.0\Contracts.dll" />
<file src="..." target="lib\netstandard2.0\Contracts.dll" />
</files>
</package>