Packagereference copy to output directory

Packagereference copy to output directory DEFAULT

Copy files from Nuget package to output directory with MsBuild in .csproj and dotnet pack command

It is possible to copy files without the file, if you create your nuget from the file as described here.

And to copy files from nuget to output directory, create a file with the following content:

In your file add:

The paths and names can of course be freely chosen.

This should copy all files to a folder called in the output directory!

Ok I finally found the solution and that includes a file and a file as well.

The just needs to include this

In the you put everything related to the Nuget package

And finally the . Careful! The file is located in the Nuget cache of the machine. You will be able to see it at the root of your project in Visual Studio but not in the Windows Explorer (in Windows at least). So if you modify the file in Visual Studio, it will modify it for ALL other projects on this machine referencing the same Nuget package (and same version).

I generate the Nuget package using the command (now that I've more experience I know that doesn't work well with a file, there are several bugs) Here is the result:

enter image description here

Finally I can just install my package and during the build process, the file will be copied out of the Nuget cache to the output directory of my project.

I think that How do you set nuget contentFiles CopyToOutput value to true when using a .Net Standard library .csproj? provides a better answer to this question.

You can set to true in the .csproj to declare the nuget content file as "CopyToOutput=true". That way any project referencing the nuget will have the content file marked with in the referring csproj file, instructing msbuild to copy the content file to the ouput directory:

In the .csproj of the nuget project:


Package references () in project files

Package references, using the node, manage NuGet dependencies directly within project files (as opposed to a separate file). Using PackageReference, as it's called, doesn't affect other aspects of NuGet; for example, settings in files (including package sources) are still applied as explained in Common NuGet configurations.

With PackageReference, you can also use MSBuild conditions to choose package references per target framework, or other groupings. It also allows for fine-grained control over dependencies and content flow. (See For more details NuGet pack and restore as MSBuild targets.)

Project type support

By default, PackageReference is used for .NET Core projects, .NET Standard projects, and UWP projects targeting Windows 10 Build 15063 (Creators Update) and later, with the exception of C++ UWP projects. .NET Framework projects support PackageReference, but currently default to . To use PackageReference, migrate the dependencies from into your project file, then remove packages.config.

ASP.NET apps targeting the full .NET Framework include only limited support for PackageReference. C++ and JavaScript project types are unsupported.

Adding a PackageReference

Add a dependency in your project file using the following syntax:

Controlling dependency version

The convention for specifying the version of a package is the same as when using :

In the example above, 3.6.0 means any version that is >=3.6.0 with preference for the lowest version, as described on Package versioning.

Using PackageReference for a project with no PackageReferences

Advanced: If you have no packages installed in a project (no PackageReferences in project file and no packages.config file), but want the project to be restored as PackageReference style, you can set a Project property RestoreProjectStyle to PackageReference in your project file.

This may be useful, if you reference projects which are PackageReference styled (existing csproj or SDK-style projects). This will enable packages that those projects refer to, to be "transitively" referenced by your project.

PackageReference and sources

In PackageReference projects, the transitive dependency versions are resolved at restore time. As such, in PackageReference projects all sources need to be available for all restores.

Floating Versions

Floating versions are supported with :

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 metadata to control this behavior.

The following metadata tags control dependency assets:

TagDescriptionDefault Value
IncludeAssetsThese assets will be consumedall
ExcludeAssetsThese assets will not be consumednone
PrivateAssetsThese assets will be consumed but won't flow to the parent projectcontentfiles;analyzers;build

Allowable values for these tags are as follows, with multiple values separated by a semicolon except with and which must appear by themselves:

compileContents of the folder and controls whether your project can compile against the assemblies within the folder
runtimeContents of the and folder and controls whether these assemblies will be copied out to the build output directory
contentFilesContents of the folder
build and in the folder
buildMultitargeting(4.0) and in the folder, for cross-framework targeting
buildTransitive(5.0+) and in the folder, for assets that flow transitively to any consuming project. See the feature page.
analyzers.NET analyzers
nativeContents of the folder
noneNone of the above are used.
allAll of the above (except )

In the following example, everything except the content files from the package would be consumed by the project and everything except content files and analyzers would flow to the parent project.

Note that because is not included with , targets and props will flow to the parent project. Consider, for example, that the reference above is used in a project that builds a NuGet package called AppLogger. AppLogger can consume the targets and props from , as can projects that consume AppLogger.


When is set to in a file, this marks a package as a development-only dependency, which prevents the package from being included as a dependency in other packages. With PackageReference (NuGet 4.8+), this flag also means that it will exclude compile-time assets from compilation. For more information, see DevelopmentDependency support for PackageReference.

Adding a PackageReference condition

You can use a condition to control whether a package is included, where conditions can use any MSBuild variable or a variable defined in the targets or props file. However, at presently, only the variable is supported.

For example, say you're targeting as well as but have a dependency that is applicable only for . In this case you don't want a project that's consuming your package to add that unnecessary dependency. To prevent this, you specify a condition on the as follows:

A package built using this project will show that Newtonsoft.Json is included as a dependency only for a target:

The result of applying a Condition on PackageReference with VS2017

Conditions can also be applied at the level and will apply to all children elements:


This feature is available with NuGet 5.0 or above and with Visual Studio 2019 16.0 or above.

Sometimes it is desirable to reference files in a package from an MSBuild target. In based projects, the packages are installed in a folder relative to the project file. However in PackageReference, the packages are consumed from the global-packages folder, which can vary from machine to machine.

To bridge that gap, NuGet introduced a property that points to the location from which the package will be consumed.


Additionally NuGet will automatically generate properties for packages containing a tools folder.

MSBuild properties and package identities do not have the same restrictions so the package identity needs to be changed to an MSBuild friendly name, prefixed by the word . To verify the exact name of the property generated, look at the generated nuget.g.props file.

PackageReference Aliases

In some rare instances different packages will contain classes in the same namespace. Starting with NuGet 5.7 & Visual Studio 2019 Update 7, equivalent to ProjectReference, PackageReference supports . By default no aliases are provided. When an alias is specified, all assemblies coming from the annotated package with need to be referenced with an alias.

You can look at sample usage at NuGet\Samples

In the project file, specify the aliases as follows:

and in the code use it as follows:

NuGet warnings and errors

This feature is available with NuGet 4.3 or above and with Visual Studio 2017 15.3 or above.

For many pack and restore scenarios, all NuGet warnings and errors are coded, and start with . All NuGet warnings and errors are listed in the reference documentation.

NuGet observes the following warning properties:

  • , treat all warnings as errors
  • , treat specific warnings as errors
  • , hide specific warnings, either project-wide or package-wide.


Suppressing NuGet warnings

While it is recommended that you resolve all NuGet warnings during your pack and restore operations, in certain situations suppressing them is warranted. To suppress a warning project wide, consider doing:

Sometimes warnings apply only to a certain package in the graph. We can choose to suppress that warning more selectively by adding a on the PackageReference item.

Suppressing NuGet package warnings in Visual Studio

When in Visual Studio, you can also suppress warnings through the IDE.

Locking dependencies

This feature is available with NuGet 4.9 or above and with Visual Studio 2017 15.9 or above.

Input to NuGet restore is a set of Package References from the project file (top-level or direct dependencies) and the output is a full closure of all the package dependencies including transitive dependencies. NuGet tries to always produce the same full closure of package dependencies if the input PackageReference list has not changed. However, there are some scenarios where it is unable to do so. For example:

  • When you use floating versions like . While the intention here is to float to the latest version on every restore of packages, there are scenarios where users require the graph to be locked to a certain latest version and float to a later version, if available, upon an explicit gesture.

  • A newer version of the package matching PackageReference version requirements is published. E.g.

    • Day 1: if you specified but the versions available on the NuGet repositories were 4.1.0, 4.2.0 and 4.3.0. In this case, NuGet would have resolved to 4.1.0 (nearest minimum version)

    • Day 2: Version 4.0.0 gets published. NuGet will now find the exact match and start resolving to 4.0.0

  • A given package version is removed from the repository. Though does not allow package deletions, not all package repositories have this constraints. This results in NuGet finding the best match when it cannot resolve to the deleted version.

Enabling lock file

In order to persist the full closure of package dependencies you can opt-in to the lock file feature by setting the MSBuild property for your project:

If this property is set, NuGet restore will generate a lock file - file at the project root directory that lists all the package dependencies.


Once a project has file in its root directory, the lock file is always used with restore even if the property is not set. So another way to opt-in to this feature is to create a dummy blank file in the project's root directory.

behavior with lock file

If a lock file is present for project, NuGet uses this lock file to run . NuGet does a quick check to see if there were any changes in the package dependencies as mentioned in the project file (or dependent projects' files) and if there were no changes it just restores the packages mentioned in the lock file. There is no re-evaluation of package dependencies.

If NuGet detects a change in the defined dependencies as mentioned in the project file(s), it re-evaluates the package graph and updates the lock file to reflect the new package closure for the project.

For CI/CD and other scenarios, where you would not want to change the package dependencies on the fly, you can do so by setting the to :

For dotnet.exe, run:

For msbuild.exe, run:

You may also set this conditional MSBuild property in your project file:

If locked mode is , restore will either restore the exact packages as listed in the lock file or fail if you updated the defined package dependencies for the project after lock file was created.

Make lock file part of your source repository

If you are building an application, an executable and the project in question is at the start of the dependency chain then do check in the lock file to the source code repository so that NuGet can make use of it during restore.

However, if your project is a library project that you do not ship or a common code project on which other projects depend upon, you should not check in the lock file as part of your source code. There is no harm in keeping the lock file but the locked package dependencies for the common code project may not be used, as listed in the lock file, during the restore/build of a project that depends on this common-code project.


If has a dependency on a version and also references that depends on version , then the lock file for will list a dependency on version . However, when is built, its lock file will contain a dependency on version and not as listed in the lock file for . Thus, the lock file of a common code project has little say over the packages resolved for projects that depend on it.

Lock file extensibility

You can control various behaviors of restore with lock file as described below:

NuGet.exe optiondotnet optionMSBuild equivalent optionDescription
RestorePackagesWithLockFileOpts into the usage of a lock file.
RestoreLockedModeEnables locked mode for restore. This is useful in CI/CD scenarios where you want repeatable builds.
RestoreForceEvaluateThis option is useful with packages with floating version defined in the project. By default, NuGet restore will not update the package version automatically upon each restore unless you run restore with this option.
NuGetLockFilePathDefines a custom lock file location for a project. By default, NuGet supports at the root directory. If you have multiple projects in the same directory, NuGet supports project specific lock file


The property lets you specify additional compatible framework versions for projects that your project references and NuGet packages that your project consumes.

If you specify a package dependency using but that package doesn't contain assets that are compatible with your projects's target framework, the property comes into play. The compatibility of the referenced package is rechecked using each target framework that's specified in . When a or a is referenced through , the NU1701 warning will be raised.

Refer to the table below for examples of how affects compatibility.

Project frameworkAssetTargetFallbackPackage frameworksResult
.NET Framework 4.7.2.NET Standard 2.0.NET Standard 2.0
.NET Core App 3.1.NET Standard 2.0, .NET Framework 4.7.2.NET Standard 2.0
.NET Core App 3.1.NET Framework 4.7.2Incompatible, fail with
.NET Core App 3.1net472;net471.NET Framework 4.7.2.NET Framework 4.7.2 with

Multiple frameworks can be specified using as a delimiter. To add a fallback framework you can do the following:

You can leave off if you wish to overwrite, instead of add to the existing values.


If you are using a .NET SDK based project, appropriate values are configured and you do not need to set them manually.

was an earlier feature that attempted to address this challenge, but it is fundamentally broken and should not be used. To migrate from to , simply change the property name.

  1. Wanted parts craigslist los
  2. Zelda captured memories
  3. Yamaha blaster carb diagram

NuGet / Home Public

I was linked here from as this issue is supposedly "identical". I would question that claim but the original got closed and there seems nothing I can do about it, so I will add my issue description here.

I have a NuGet package that delivers a set of PowerShell scripts (.ps1 files).

The intended usage is to deliver these files into the target project as a folder in the filesystem directly under the project the package is installed into (e.g. installing into C:\Foo\Foo.csproj should create C:\Foo\xxx\yyy.ps1).

When I use VS2017 in packages.config mode, it works fine.

When I use VS2017 in PackageReference mode, none of the files show up in either the filesystem or Solution Explorer.

I tried both using just "/content" paths and the new contentFiles feature. Neither option made anything show up in my project. I cannot distribute my scripts anymore. I am currently looking at using Paket, which is a 3rd party NuGet alternative that appears to be far more flexible and easily usable. It is a shame to see NuGet un-fixing the problems that NuGet once fixed!


dotnet / msbuild Public

I'm trying to use PhantomJS NuGET package, but it's not possible with :

<PackageReferenceInclude="PhantomJS"Version="2.1.1"> <IncludeAssets>all</IncludeAssets> </PackageReference>

It does not do anything. I'd expect it to copy the files inside PhantomJS package to the output directory so I could use the binary file inside the package.

I think does not have support using packages such as PhantomJS which have no .NET code in it, just random files.

I suggest a feature to be able to copy files from a NuGET package to output directory

<PackageReferenceInclude="PhantomJS"Version="2.1.1"> <CopyToOutputDirectory>tools/*</CopyToOutputDirectory> <!-- new feature here --> </PackageReference>

Note that the PhantomJS has folder called "tools" inside, that needs to be copied to output directory to make it usable in the app.


Copy to directory packagereference output

Managing output in the .NET SDK projects

, Author: Cezary PiΔ…tek

With the new SDK format for .NET projects, it’s much easier to manage with the project’s dependencies. In most scenarios references added with standard mechanism (Visual Studio or ) result in sufficient content in the output directory. However, sometimes we want to do something non-standard that requires a slightly different set of components in the output dir - simply speaking we expect to see there either more or fewer files. The content of the output directory can be controlled with different properties inside the project file. Documentation for new format, as well as for related properties, is scattered across different MSDN documents, so I decided to create this blog post as a reference to what I’ve recently learned and discovered about the project’s options that affect the content of the output directory.

An example solution πŸ”—︎

Let’s take a sample solution with the following projects and references structure:

sample solution

The default setup πŸ”—︎

By default, references to other projects are added with the following entry in the file:

After we compile our solution, the and files of the referenced projects are copied to the output directory - by default . The output location can be changed by defining parameter or, if you only need to skip the part, just set . We can see the output for the default settings on the following screenshot:

default output

As you probably notice, the library files from referenced NuGet packages are not copied to the output dir. If our project was a program (not a library) with the following configuration:

the output should contain libraries from the all NuGet packages (referenced directly and non-directly) as well:

output of the application project

Enriching the output dir πŸ”—︎

Sometimes you might notice that, despite what I told you in the previous paragraph, some libraries form NuGet package are copied to the output directory. This can be caused by custom build scripts that are shipped together with given NuGet package - you can find them in directory inside the NuGet package (they must obey naming convention or ). An example could be NUnit3TestAdapter package:

Content of NUnit3TestAdapter package

You can also verify what you are getting extra from all your NuGet dependencies in a single place using MSBuildStructuredLog Viewer

extra targets

This tool is very helpful for investigating issues when you are experiencing unexpected behaviors during the build process. You can, of course, control what IS and what IS NOT consumed from the NuGet package with and properties - please check Controlling dependency assets for more details. To prevent loading build scripts ( and ) from the dependent packages just set on the .

UPDATE 2019-11-07: You can globally block loading *.props and *.targets files from nuget packages by setting . You can read more about that here

If we want to enforce copying NuGet dependencies to the output directory for the library projects, we can do that by setting :

After rebuild, the output directory should look as follows:

library with dependencies in output dir

To our surprise, copied also a couple of files into the output. These libraries come (directly and indirectly) from and (depends on the selected ) packages which are referenced implicitly.

If you want to copy all framework and runtime dependencies as well, you have to set and properties:

You can read more about in the .NET Core application deployment article.

Putting the output dir on the diet πŸ”—︎

As you saw in the paragraph about the default setup, the files of the referenced projects are copied to the output dir. This default behavior can be changed by setting property on the .

metadata is responsible for controlling well known property for the dependent project assembly file. Here’s an excerpt of comment from Microsoft.Common.CurrentVersion.targets definition:

This option can be used to optimize build performance. Switching it to should reduce the amount of during the build. If we would like to apply this behavior to all library projects in the solution, it can be achieved by adding the following code into :

This custom target has to be run after because before that the item group contains only direct project references - updating earlier will result with some dependencies still being copied to the output. Besides the group, it also updates , because this one is used later by to determine which files should be copied to the output directory (actually this collection goes through the following conversions in the meantime). For our purpose, updating should be enough but I wanted to preserve the consistency. It took me two evenings to come up with this working solution ;) If you are going to use it, please pay attention to the attribute - maybe this should be adjusted to your needs.

Although the library B is not copied to the output, it’s still a dependency for library A. If it is, for example, a design-time dependency and we what to get rid of it from runtime dependencies, we can achieve it by setting property to :

Summary πŸ”—︎

As you saw, there are multiple mechanisms that allow controlling what is in the output directory. It’s good to be aware of their existence to avoid surprises and losing hours for fighting with something that appears in our output dir in spite of our expectations.

Products recommended for highly effective .NET Developers:

How to Copy Any Files to One Folder to Another Folder in C# Windows Application 2020 - Part 1

The member suddenly fell out for no reason at all and I could not put it back. - Come on, do not be shy - my friend whispered to me. - I want you to fuck her first. She already wants to, stop licking, she's curious, your dick, to test. Do not mind, she really, substitute you, please her and yourself.

You will also be interested:

Rita warned Anton. Her hands began to stroke his back, small claws slightly left marks on the man's back, causing him a scattering of goose bumps. Rita knelt down and moved her hands up the nomes, gradually shifting to the man's buttocks while her lips left tender kisses in front, gradually getting closer to the erect penis.

With her hot mouth, she caught the coveted trunk of Anton and took it in, at the same time squeezing the man's buttocks and. Literally pushed it into her mouth.

1711 1712 1713 1714 1715