I have 3 .net standard SDK projects(Utils, Reporting and Testing) that I want to pack them into one nuget package called Shared and upload it in my local package management system to be able to be used in my other projects. I was thinking to use the csproj file(s) to fill all the package information so I don't have to use nuspec file(s). One way I tried is to create a new .net standard project called Shared that references all the first 3 projects and only fill the Shared.csproj.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Copyright>Copyright (c) Me</Copyright>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<SkipCopyBuildProduct>true</SkipCopyBuildProduct>
<GenerateDependencyFile>False</GenerateDependencyFile>
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Utils.csproj" />
<ProjectReference Include="..\Reporting.csproj" />
<ProjectReference Include="..\Testing.csproj" />
</ItemGroup>
</Project>
I've tried this msbuild command:
dotnet msbuild -t:pack=Shared.csproj;-p:Configuration=Release;PackageOutputPath=.\release;
and this nuget cli command:
nuget pack Shared.csproj -Build -IncludeReferencedProjects -Prop Configuration=Release
but they don't work. I'm not sure which one is more suited.
Are there more suited alternatives?
Later edit: I've added my code to github with #mu88's suggestion to not create a project only for grouping my other projects but I don't get the 3 projects in my nupkg's libs folder. Do I also specify each project in the dependencies.group section?
I'd personally recommend using a .nuspec file - using a project only as a container to ship multiple assemblies together without any behavior at all doesn't seem right to me.
Such a .nuspec would look like this:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>My.Package</id>
<version>1.0.0</version>
<description>My package</description>
<authors>Me</authors>
<dependencies>
<group targetFramework="netstandard2.0" />
</dependencies>
</metadata>
<files>
<file src="*\bin\Debug\netstandard2.0\*.dll" target="lib\netstandard2.0" />
</files>
</package>
And you have to call nuget pack .\.nuspec (using PowerShell).
The newer approach would be to not use .nuspec at all, but ship the three projects as three independent NuGet packages.
Related
From following question How do I list all installed NuGet packages?
I need to get a list of nuget packages from MSBuild itself.
What I try to do:
<Target Name="test" AfterTargets="ResolveReferences">
<ItemGroup>
<BuildOutputInPackage Include="#(ReferenceCopyLocalPaths)"/>
</ItemGroup>
<Message Text="Files #(BuildOutputInPackage -> '%(identity)', ', ')" Importance="high"/>
</Target>
Above code return all references whether its nuget or project references dlls. How exactly to return a list of nuget package that currently project *.csproj used?
Format i.e: packageid:Portable.BouncyCastle version = "1.9.0"
I use old classic non-sdk csproj template and .NET 4.8 and <PackageReference> not packages.config files.
Its very bad to read *.csproj and do regex to get a list of <packageReferences. Maybe there's a recommended MSBuild macro to do this like code shown above <Target....
ReferenceCopyLocalPaths is only "Paths to files that should be copied to the local directory." It is not all resolved references.
Yes, don't regex the project file. There is no need. PackageReference is an ItemGroup.
<Target Name="DisplayPackageReference">
<Message Text="#(PackageReference ->'packageid:%(identity) version = "%(version)"', '%0d%0a')" />
</Target>
But note that PackageReference is what the project is asking for and the version can be floating, e.g Version="3.6.*". PackageReference won't give you the package version that the package reference was resolved to.
If you need to know the specific version used, then you may need to install dotnet, use an exec task to run dotnet list "$(MSBuildProjectFile)" package, and parse the command's output.
Very thankful to Jonathan Dodds for his answer above. I combined some approach with his #(PackageReference) idea to get a version of currently referenced nuget package in old classic csproj template. Because a referenced version will not work with #(PackageReference) only. Also dotnet list not worked well in old classic csproj template (non-sdk).
A code below do following:
(Note this approach is not 100% organic, MSBuild should provide a simple target for that):
Get all references that maybe be nuget or non-nuget (DLLs, etc).
Get only references that included inside #(PackageReference). Jonathan Doods approach above.
Get .nuspec file for that package to know exactly what version current *.csproj referenced.
Create a new nuspec file for current project. with a list of dependencies.
You can then call nuget.exe pack ProjectPath.csproj a ProjectName.nupkg nuget will generated.
Use this code inside Directory.Build.targets or within your .csproj file.
<Target Name="GenerateNuspecFile">
<ItemGroup>
<!-- Get all references -->
<MyReference Include="#(ReferenceCopyLocalPaths)" Condition="%(extension) == '.dll'">
<FirstDir>$([System.IO.Directory]::GetParent(%(RelativeDir)))</FirstDir>
<LibDir>$([System.IO.Path]::GetFileNameWithoutExtension(%(MyReference.FirstDir)))</LibDir>
<SecondDir>$(FirstDir)</SecondDir>
<SecondDir Condition="$(LibDir) != 'lib'">$([System.IO.Directory]::GetParent(%(MyReference.FirstDir)))</SecondDir>
<VersionDir>$([System.IO.Directory]::GetParent(%(MyReference.SecondDir)))</VersionDir>
<PackageDir>$([System.IO.Directory]::GetParent(%(MyReference.VersionDir)))</PackageDir>
<PackageID>$([System.IO.Path]::GetFileName(%(MyReference.PackageDir)))</PackageID>
<NuspecFile>%(MyReference.VersionDir)\%(MyReference.PackageID).nuspec</NuspecFile>
</MyReference>
<!-- Get Non nuget references -->
<ExcludedReference Condition="#(MyReference) != ''" Include="#(MyReference -> '%(PackageID)')" Exclude="#(PackageReference -> '%(identity)')"/>
<!-- Get nuget references after exclude non-nuget references -->
<MyPackage Condition="#(MyReference) != ''" Include="#(MyReference -> '%(PackageID)')" Exclude="#(ExcludedReference -> '%(identity)')"/>
<!-- Read Nuspec File -->
<NuspecContent Condition="#(NuspecFile) != ''" Include="%(MyPackage.NuspecFile)">
<Content>$([System.IO.File]::ReadAllText(%(fullpath)))</Content>
<PackageIDRegex><id>(.*?)</id></PackageIDRegex>
<PackageID>$([System.Text.RegularExpressions.Regex]::Match('%(NuspecContent.Content)', '%(NuspecContent.PackageIDRegex)' ))</PackageID>
<PackageID>$([System.String]::Copy('%(NuspecContent.PackageID)').Replace('<id>','').Replace('</id>', '').Trim())</PackageID>
<VersionRegex><version>(.*?)</version></VersionRegex>
<Version>$([System.Text.RegularExpressions.Regex]::Match('%(NuspecContent.Content)', '%(NuspecContent.VersionRegex)' ))</Version>
<Version>$([System.String]::Copy('%(NuspecContent.Version)').Replace('<version>','').Replace('</version>', '').Trim())</Version>
</NuspecContent>
</ItemGroup>
<!-- Generate Nuspec File with dependencies-->
<PropertyGroup>
<NewLine>%0d%0a</NewLine>
<Space2>%20%20</Space2>
<Space4>$(Space2)$(Space2)</Space4>
<Space6>$(Space4)$(Space2)</Space6>
<HasDependencies>false</HasDependencies>
<HasDependencies Condition="#(MyPackage) != ''">true</HasDependencies>
<Nuspec>$(Nuspec)<?xml version="1.0" encoding="utf-8"?>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)<package >$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space2)<metadata>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space4)<id>$id$</id>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space4)<version>$version$</version>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space4)<title>$title$</title>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space4)<authors>$author$</authors>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space4)<owners>$author$</owners>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space4)<requireLicenseAcceptance>false</requireLicenseAcceptance>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space4)<licenseUrl>https://Your Company.com</licenseUrl>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space4)<icon>PackageIcon.png</icon>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space4)<projectUrl>http://Your Company.com</projectUrl>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space4)<description>$description$</description>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space4)<releaseNotes>$description$</releaseNotes>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space4)<copyright>$copyright$</copyright>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space4)<tags>$title$ Your Company Your Company.com</tags>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space4)<dependencies>$(NewLine)</Nuspec>
<Nuspec Condition="$(HasDependencies)">$(Nuspec)$(Space6)<group targetFramework=".NETFramework4.8">$(NewLine)</Nuspec>
<Nuspec Condition="$(HasDependencies)">$(Nuspec)#(NuspecContent -> '$(Space6)<dependency id="%(PackageID)" version="%(Version)"/>', '$(NewLine)')$(NewLine)</Nuspec>
<Nuspec Condition="$(HasDependencies)">$(Nuspec)$(Space6)</group>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space4)</dependencies>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space2)</metadata>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space2)<files>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space4)<file src="..\**\PackageIcon.png"/>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)$(Space2)</files>$(NewLine)</Nuspec>
<Nuspec>$(Nuspec)</package>$(NewLine)</Nuspec>
</PropertyGroup>
<WriteLinesToFile Lines="$(Nuspec)" File="$(MSBuildProjectDirectory)\$(MSBuildProjectName).nuspec" Overwrite="true"/>
</Target>
The generated .nuspec file will be:
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://company.com</licenseUrl>
<icon>PackageIcon.png</icon>
<projectUrl>http://company.com</projectUrl>
<description>$description$</description>
<releaseNotes>$description$</releaseNotes>
<copyright>$copyright$</copyright>
<tags>$title$ company company.com</tags>
<dependencies>
<dependency id="Company.Globals" version="2022.7.19"/>
<dependency id="Portable.BouncyCastle" version="1.9.0"/>
</dependencies>
</metadata>
<files>
<file src="..\**\PackageIcon.png"/>
</files>
</package>
Its really to hard to achieve anything with MSBuild. Maybe you can create a console app for that and just call console app directly with <Exec Command =""/>. But current approach is friendly with MSBuild. Its not 100% organic approach. MSBuild should provide us a target to get a referenced nuget packages with its referenced version.
I'm attempting to migrate to using MSBuild Pack support for using .csproj to generate a projects NuGet package where during development local .dll's are used to build the project but they need to be replaced/swapped to reference an external NuGet package in the generated .nuspec when Using MSBuild to "pack" the project.
The closest documented example of this use-case I could find is Replacing one library from a restore graph
where it suggests you can replace an external NuGet reference:
<PackageReference Include="Newtonsoft.Json" Version="9.0.1">
<ExcludeAssets>All</ExcludeAssets>
</PackageReference>
Which overrides the package to reference to a local .dll instead:
<Reference Include="Newtonsoft.Json.dll" />
I'm trying to do something similar where the project should build against local .dll's that were injected as an artifact from a dependent TeamCity/CI build:
<Reference Include="..\..\lib\net45\ServiceStack.Interfaces.dll" />
<Reference Include="..\..\lib\net45\ServiceStack.Text.dll" />
<Reference Include="..\..\lib\net45\ServiceStack.Common.dll" />
But when using ExcludeAssets=All as per the documentation:
<PackageReference Include="ServiceStack.Common" Version="5.0.0">
<ExcludeAssets>All</ExcludeAssets>
</PackageReference>
The PackageReference doesn't get exported in the generated dependency list, e.g:
<group targetFramework=".NETFramework4.5" />
The closest I've come to getting the preferred behavior is to use ExcludeAssets="compile" so my local project doesn't build against it, except this behavior also gets exported in the .nuspec:
<group targetFramework=".NETFramework4.5">
<dependency id="ServiceStack.Common" version="5.4.0" exclude="Compile,Build,Analyzers" />
</group>
I only want to avoid building against it locally but have it exported as a normal dependency. The other issue with this approach is that I need it to reference a package that hasn't been published to NuGet yet (as all packages are published in lock-step), e.g:
<!-- v5.5.0 is the new version to publish -->
<PackageReference Include="ServiceStack.Common" Version="5.5.0" ExcludeAssets="compile"/>
The build fails that it can't find the unpublished package:
[NU1102] Unable to find package ServiceStack.Common with version (>= 5.5.0)
Effectively I need someway to "inject" the exact dependencies and version I need in the generated .nuspec so it's included in the generated .nuspec dependency list, e.g:
<group targetFramework="net45">
<dependency id="ServiceStack.Common" version="5.5.0" />
</group>
<group targetFramework=".netstandard2.0">
<dependency id="ServiceStack.Common" version="5.5.0" />
</group>
How can we inject a custom dependency in MSBuild generated .nuspec?
Is there some way I can manually declare <dependency/> as above so it's only used when MSBuild/NuGet packs the project? Otherwise is there a way to apply some XML transform to the generated .nuspec so I can manipulate the XML in the .nuspec before it's packed/compressed?
Basically I'm only interested in injecting dependencies when the "pack" target is run so it's ignored/inert in all other targets.
You've probably found another solution for this by now, but I "succeeded" in doing this, by adding some custom targets to the csproj. The solution did leave me with the feeling that maybe I shouldn't have done it.
The steps were
Inject a step before the package generation target, that disables the nupkg generation
Inject a step after the package generation target that modifies the generated nuspec file, and call the package generation target again.
I've modified my fix below so it injects the dependencies mentioned in the post. I've disabled validation here (NoPackageAnalysis=true). You can put it in a .target file and import it from the csproj.
<Project>
<!-- Disable nupkg generation before running pack -->
<Target Name="__DisablePacking" BeforeTargets="GenerateNuspec" Condition="$(NuspecFile) == ''">
<PropertyGroup>
<ContinuePackingAfterGeneratingNuspec>false</ContinuePackingAfterGeneratingNuspec>
</PropertyGroup>
</Target>
<!-- Modify the generated nuspec file and rerun the pack target -->
<Target Name="__EnablePackingAndInjectDependencies" AfterTargets="Pack" Condition="$(NuspecFile) == ''">
<!-- Get the nuspec file name -->
<PropertyGroup>
<_NugetPackOutputAsProperty>#(NuGetPackOutput)</_NugetPackOutputAsProperty>
</PropertyGroup>
<ItemGroup>
<_NugetPackOutputAsItem Remove="#(_NugetPackOutputAsItem)"/>
<_NugetPackOutputAsItem Include="$(_NugetPackOutputAsProperty.Split(';'))" />
</ItemGroup>
<PropertyGroup>
<__NuspecFileName>%(_NugetPackOutputAsItem.Identity)</__NuspecFileName>
</PropertyGroup>
<!-- Create an updated dependencies, with the net46 dependencies copied to a native group -->
<PropertyGroup>
<__NuSpecUpdatedDependencies>
<group targetFramework="net45">
<dependency id="ServiceStack.Common" version="5.5.0" />
</group>
<group targetFramework=".netstandard2.0">
<dependency id="ServiceStack.Common" version="5.5.0" />
</group>
</__NuSpecUpdatedDependencies>
</PropertyGroup>
<!-- Poke them back in -->
<XmlPoke XmlInputPath="$(__NuspecFileName)"
Value="$(__NuSpecUpdatedDependencies)"
Query="/n:package/n:metadata/n:dependencies"
Namespaces="<Namespace Prefix='n' Uri='http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd' />">
</XmlPoke>
<!-- call the pack operation again -->
<PropertyGroup>
<ContinuePackingAfterGeneratingNuspec>true</ContinuePackingAfterGeneratingNuspec>
</PropertyGroup>
<Msbuild
Projects="$(MSBuildProjectFullPath)"
Targets="Pack"
Properties="NuspecFile=$(__NuspecFileName);NoPackageAnalysis=true">
</Msbuild>
</Target>
</Project>
(I was looking to inject a native0.0 framework dependency so my packages could be consumed by c++/cli projects, in case someone should know of an easier way to do it).
Interesting question, and when I looked around for answers
I found Another discussion in Stackoverflow
Where in one of the comments - there was an indication that the pack command only works with framework projects with 4.6 and above - not 4.5.
The .Net Standard 2.0 has to match 4.6.1 based on this blog entry from Microsoft
I have a .NET Standard 2.0 project called ProjectName.Logging with a ProjectName.Logging.nuspec file.
This file file is referenced in the .csproj of my project
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<NuspecFile>ProjectName.Logging.nuspec</NuspecFile>
</PropertyGroup>
Here is my .nuspec
<?xml version="1.0"?>
<package >
<metadata>
<id>ProjectName.Logging</id>
<version>1.2.1</version>
<authors>Jérôme MEVEL</authors>
<description>Just a logging component</description>
<dependencies>
<dependency id="Dapper" version="1.50.5" />
<dependency id="Another.Project" version="1.1.1" />
<dependency id="Microsoft.Extensions.DependencyInjection" version="2.1.1" />
<dependency id="Microsoft.Extensions.Logging" version="2.1.1" />
<dependency id="Microsoft.Extensions.Logging.Abstractions" version="2.1.1" />
<dependency id="NLog" version="4.5.8" />
<dependency id="NLog.Extensions.Logging" version="1.2.1" />
<dependency id="NLog.Web.AspNetCore" version="4.6.0" />
<dependency id="System.Data.SqlClient" version="4.5.1" />
</dependencies>
</metadata>
<files>
<file src="bin\Release\netstandard2.0\ProjectName.Logging.dll" target="lib/netstandard2.0/ESHCloud.Logging.dll" />
<file src="ProjectName.Logging.targets" target="build/ProjectName.Logging.targets" />
<file src="NLog/Nlog.config" target="content/Nlog.config" />
</files>
</package>
As you can see I manually include the ProjectName.Logging.dll file and I even have to include Release because the usage of the MsBuild variable $(Configuration) doesn't work in my .nuspec file.
I pack the project by executing this command in my project's directory
dotnet pack --output C:/Nuget --force
and if I remove the <files> element from my .nuspec when I run the dotnet pack command, my generated Nuget package is completely empty.
On the other hand if I run the dotnet pack command without a .nuspec file, absolutely everything in my project is included in the Nuget package.
So what's the deal with the dotnet pack command? I don't understand what am I doing wrong.
How to include my project's DLL in the Nuget package without having to specify the configuration (Debug or Release)?
One last thing: I don't want to use the nuget pack command.
I played enough with Nuget on our VSTS servers (recently renamed Azure DevOps) and I don't have full control over these build servers (my manager has but he seems too busy to care about it).
So to sum up, nuget pack is not an option for me. I want to use dotnet pack along with a .nuspec file.
Thank you
To add your DLL without specifying the configuration use a glob pattern:
<file src="runtimes\**" target="runtimes/"/>
If you use nuget.exe you could use a replacement token:
<file src="bin\$configuration$\netstandard2.0\*.dll" target="lib\netstandard2.0\"/>
If you really need to use the nuspec file you're better off using nuget.exe. If you don't want to use nuget.exe drop the nuspec. I've done a fair amount of work with dotnet and nupkgs the last few weeks and mixing nuspec with project files is fiddly.
You can put the majority of the nupkg meta-data directly in the csproj:
<PropertyGroup>
<PackageId>Subor.nng.NETCore</PackageId>
<PackageVersion>0.0.2</PackageVersion>
<Authors>Subor</Authors>
...
</PropertyGroup>
This is the recommended approach when using the dotnet CLI. Likewise for msbuild with the PackageReference format.
Here's an example of a project I've been working on. dotnet pack builds a package bin/Debug/ and dotnet pack --configuration Release builds this nuget.org package.
Everything in the project should not get copied into the nupkg. In Visual Studio check the Properties of the files and make sure everything isn't flagged as "Content", etc.. Also check the project files to see if files are getting added that shouldn't be. Look for (miss-)use of <PackagePath> and <IsPackable>.
Without knowing the particulars of your project, I'll mention trying some of the arguments to dotnet pack.
I have an .exe app that I need to distribute with my C# app when it builds. I am trying to use Nuget to package it so that it will be included in the build root directory when building but am having trouble getting the behaviour I want.
Here is what I've got in my .nuspec file:
<?xml version="1.0"?>
<package>
<metadata>
<id>my.id</id>
<version>1.0.0</version>
<authors>me</authors>
<owners>me</owners>
<licenseUrl>myurl</licenseUrl>
<projectUrl>myurl</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A copy of an .exe so we can easily distribute it
with our applications without needing to include it in our VCS repo</description>
<releaseNotes>Initial test version</releaseNotes>
<copyright>Copyright 2018</copyright>
<dependencies>
</dependencies>
<packageTypes>
</packageTypes>
<contentFiles>
<files include="any\any\myexe.exe" buildAction="None" copyToOutput="true" />
</contentFiles>
</metadata>
<files>
<file src="content\myexe.exe" target="content" />
</files>
</package>
This puts the myexe.exe file to my VS project when I install the Nuget Package but it does not copy the file when I build. What I'd like is for the file to by installed with my other app files when building and to keep it out of my VS project.
I've been reading docs here but am not sure how to make the nuspec file.
More Details:
Nuget 4.5.1
Visual Studio 2015
Note: the <files> and <contentFiles> might seem to be duplicating functionality. I'd like to employ both as I understand this will future-proof it for VS2017
Nuget: Including an exe as a Run-time dependency
First, I know you want to use some technologies for the future, but we have to know that these future-oriented technologies often have certain constraints and conditions.
For example, <contentFiles> is used for NuGet 4.0+ with PackageReference, neither of them is supported by Visual Studio 2015. See Using the contentFiles element for content files for some details.
If you are interested in the <contentFiles>, you can read the blog NuGet is now fully integrated into MSBuild.
Go back to our question now, according to above info, we should not use <contentFiles> when we use Visual Studio 2015. To resole this issue, we need to add a .targets file in the nuget package when you build the project:
The content of .targets file:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="$(ProjectDir)myexe.exe">
<Link>myexe.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CustomToolNamespace></CustomToolNamespace>
</None>
</ItemGroup>
</Project>
The .nuspec file like following:
<files>
<file src="build\YouNuGetPackageName.targets" target="build\YouNuGetPackageName.targets" />
<file src="content\myexe.exe" target="content\myexe.exe" />
</files>
Note: The name of the .targets file should be same as your nuget package name.
With this way, when you build your project, MSBuild/VS would copy the file myexe.exe to the output folder.
Besides, if you want to copy the file myexe.exe to other destination, you can replace the content of .targets file with a copy task, like:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CopyMyexe" BeforeTargets="Build">
<Message Text="Copy CopyMyexe to the folder."></Message>
<Copy
SourceFiles="$(ProjectDir)myexe.exe"
DestinationFolder="xxx\xxx\xx\myexe.exe"
/>
</Target>
</Project>
See Creating native packages and similar issue for some helps.
Hope this helps.
I have a .NET Standard class library project that will be built into a NuGet package. I've installed the docfx.console package so that I can generate a documentation website every time I build.
Now when another project installs my library's NuGet package, the docfx.console NuGet package also gets installed - which I don't want.
In the project properties under Package, I have selected Generate NuGet package on build. This would automatically generate the NuGet package for my library when I build it. But in this tab, I don't see anywhere where I can configure to exclude any packages.
So in order to exclude the docfx.console package, I created a .nuspec file with the following contents:
<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<!-- Required elements-->
<id>My.Library</id>
<version>1.0.1</version>
<description>My Library's project dscription.</description>
<authors>Me</authors>
<copyright>My Copyright (c)</copyright>
<!-- Optional elements -->
<dependencies>
<dependency id="docfx.console" version="2.36.1" exclude="build" />
</dependencies>
<!-- ... -->
</metadata>
<!-- Optional 'files' node -->
</package>
But it isn't working. How can I correct it to exclude the docfx.console package when building the NuGet package?
Or, is there any other way I could exclude the docfx.console package from the NuGet package?
How to exclude a package from a Class Library NuGet package?
According to the NuGet official documentation Controlling dependency assets:
You might be using a dependency purely as a development harness and
might not want to expose that to projects that will consume your
package. In this scenario, you can use the PrivateAssets metadata to
control this behavior.
<ItemGroup>
<!-- ... -->
<PackageReference Include="Contoso.Utility.UsefulStuff" Version="3.6.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<!-- ... -->
</ItemGroup>
So, just as UserName commented, you can add <PrivateAssets>all</PrivateAssets> to PackageReference of docfx.console in your project.
To accomplish this, edit your project file .csproj like following:
<ItemGroup>
<PackageReference Include="docfx.console" Version="2.36.2" PrivateAssets="All" />
</ItemGroup>
Or
<ItemGroup>
<PackageReference Include="docfx.console" Version="2.36.2">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
If you are using .nuspec file, you should move the following dependency info in your .nuspec file:
<dependencies>
<dependency id="docfx.console" version="2.36.1" />
</dependencies>