I have a solution foo.sln. All libraries within are SDK projects. However only one of them should be packed
By default
dotnet pack
tries to pack all projects. There is no exclude filter or include filter for that matter. What is the recommended process?
dotnet pack : The output is a package that is meant to be reused by other projects. dotnet publish : The output is mean to be deployed / "shipped" - it is not a single "package file" but a directory with all the project's output.
By default, dotnet pack builds the project first. If you wish to avoid this behavior, pass the --no-build option. This option is often useful in Continuous Integration (CI) build scenarios where you know the code was previously built.
This is generally also what the “Pack” command does in the context menu in Visual Studio. Packing will usually involve building the project properly and then packing it into a . nupkg file. If you look at your project output, you should see a KnockoutTest. nupkg file as well.
You select what project to pack as nuget package by setting property inside of csproj
file, like this:
<IsPackable>true</IsPackable>
- create package
<IsPackable>false</IsPackable>
- don't create package
If you don't want to specify it in each file you can create a text file named Directory.Build.props
in the directory with the following content:
<Project>
<PropertyGroup>
<IsPackable>false</IsPackable>
</PropertyGroup>
</Project>
It would be automatically included in all on the beginning of the SDK project file (csproj) in this and all nested folders, so you can specify common default values for this group of projects and if needed they could be overridden in individual csproj files.
If you don't want them to be overwritten or need to use some values defined in csproj, you should use file name Directory.Build.targets
, that would be automatically included at the end of csproj.
In our projects we use the following structure:
\
\src
<actual projects>
Directory.Build.props
\tests
<unit tests>
Directory.Build.props
Directory.Build.props
MySolution.sln
In this way, we are able to specify different common properties for test and regular projects.
One note on this is that by default only first Directory.Build.props
that found by csproj
would be applied, to change this behavior you need to add this line in the beginning of nested Directory.Build.props
files (inside of Project
tag):
<Import Project="$([MSBuild]::GetPathOfFileAbove('$(_DirectoryBuildPropsFile)', '$(MSBuildThisFileDirectory)../'))" />
More about all of this could be found here: https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2017
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With