3

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:enter image description here

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.

chrisbuttacavoli
  • 183
  • 3
  • 11
  • What does MyEventLogger.Core look like? What type of project is it? – cal5barton Dec 19 '18 at 01:46
  • Updated question with more details. It is a .NET Framework class library. – chrisbuttacavoli Dec 19 '18 at 02:18
  • Is there anything preventing you from converting your class library to a net standard library? – cal5barton Dec 19 '18 at 02:27
  • As @cal5barton said, .NET Standard 2.0 may be what you're looking for: https://learn.microsoft.com/en-us/dotnet/standard/net-standard – Dan D Dec 19 '18 at 02:39
  • I changed my library to a .NET Standard 2.0 library and receive the same error. I also tried setting my file node to: – chrisbuttacavoli Dec 19 '18 at 15:24
  • If your project is an SDK-style project (which I think is must be if you managed to test using netstandard2.0 as your target framework), then you can use `dotnet pack` or `msbuild /t:pack`, and msbuild will automatically create a nuspec, so you don't need to. But it does have its own set of opinionated conventions, so may not be suitable for all projects. – zivkan Dec 23 '18 at 16:09

2 Answers2

1

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.

chrisbuttacavoli
  • 183
  • 3
  • 11
0

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

Conrad
  • 118
  • 11
  • I don't think that is the solution. I can make a project reference, but the issue comes when I try to share the library as a NuGet package. I can't seem to figure out how to construct the .nuspec file to where it can import the DLLs into my other project. – chrisbuttacavoli Dec 19 '18 at 16:42