admin管理员组

文章数量:1024593

I create a nuget package for .Net 8 as well as with .Net Framework 4.7.2 containing .cs files only. When installing the package with old .Net project, NuGet copies the content into the project folder, and changes csproj file. Is it possible just to reference the files from the nuget cache like PackageReference does? Here's my nuspec file:

<?xml version="1.0"?> 
<package> 
  <metadata minClientVersion="3.3.0"> 
   <id>MyClient</id> 
   <version>1.0.0</version> 
   <authors>me</authors>
   <requireLicenseAcceptance>false</requireLicenseAcceptance> 
   <description>description</description> 
   <tags>myclient</tags> 
   <dependencies>
     <group targetFramework="net8.0">
        ...
     </group>
     <group targetFramework="net472">
       ...
     </group>
   </dependencies>
   <!-- Build actions for items in the contentFiles folder --> 
   <contentFiles>
      <files include="cs/**/*.*" buildAction="Compile" />
   </contentFiles> 
  </metadata> 
  <files> 
    <!-- this is for the new format -->
    <file src="myproject/MyClient.cs" target="contentFiles\cs\any\Client" />
    
    <!-- this is for the old format -->
    <file src="myproject/MyClient.cs" target="content\Client" />
  </files> 
</package>

I create a nuget package for .Net 8 as well as with .Net Framework 4.7.2 containing .cs files only. When installing the package with old .Net project, NuGet copies the content into the project folder, and changes csproj file. Is it possible just to reference the files from the nuget cache like PackageReference does? Here's my nuspec file:

<?xml version="1.0"?> 
<package> 
  <metadata minClientVersion="3.3.0"> 
   <id>MyClient</id> 
   <version>1.0.0</version> 
   <authors>me</authors>
   <requireLicenseAcceptance>false</requireLicenseAcceptance> 
   <description>description</description> 
   <tags>myclient</tags> 
   <dependencies>
     <group targetFramework="net8.0">
        ...
     </group>
     <group targetFramework="net472">
       ...
     </group>
   </dependencies>
   <!-- Build actions for items in the contentFiles folder --> 
   <contentFiles>
      <files include="cs/**/*.*" buildAction="Compile" />
   </contentFiles> 
  </metadata> 
  <files> 
    <!-- this is for the new format -->
    <file src="myproject/MyClient.cs" target="contentFiles\cs\any\Client" />
    
    <!-- this is for the old format -->
    <file src="myproject/MyClient.cs" target="content\Client" />
  </files> 
</package>

本文标签: cHow to reference NuGet content files instead of copying with packagesconfigStack Overflow