I have migrate my .NET Framework project to a .NET Standard project.
In the .NET Framework project i have a .nuspec file with additional file config and create the nuget package with "NuGet.exe pack"
<files>
<file src="Install.ps1" target="tools\Install.ps1" />
</files
In the .NET Standard project i have not longer a nuspec file and switch to "msbuild -t:Pack" to create the nuget package. I have try to set the install.ps1 to (BuildAction = Content) but then i see a warning in the log "Issue: PowerShell file out side tools folder." And in the nupkg file the directory is "content\tools\Install.ps1" i need "tools\Install.ps1".
To get file into a different path in the package you can use the <PackagePath> element in the <Content> element like this:
<ItemGroup>
<Content Include="install.ps1">
<PackagePath>tools\</PackagePath>
</Content>
</ItemGroup>
(providing the install.ps1 is in the root of your project, otherwise you'll have to adjust the Include attribute value)
For more information check out the docs about the pack MsBuild Target here:
https://github.com/NuGet/Home/wiki/Adding-nuget-pack-as-a-msbuild-target
I have try to set the install.ps1 to (BuildAction = Content) but then i see a warning in the log "Issue: PowerShell file out side tools folder." And in the nupkg file the directory is "content\tools\Install.ps1" i need "tools\Install.ps1"
When you use msbuild -t:Pack to create the nuget package, msbuild/VS expects the files to be in content folder. But if you still want to the install.ps1 file in the tools directory, you can still use the .nuspec file and nuget.exe to pack the package.
The detail steps to pack package:
Create the .nuspec as below settings:
<?xml version="1.0"?>
<package >
<metadata>
<id>TestInstall.ps1</id>
<version>1.0.0</version>
<authors>Test</authors>
<owners>Test</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package description</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>Tag1 Tag2</tags>
</metadata>
<files>
<file src="Install.ps1" target="tools" />
<file src="bin\Debug\netstandard1.4\TestInstall.ps1.dll" target="lib\netstandard1.4" />
</files>
</package>
Then use the command line: nuget.exe pack xxx.nuspec to pack the package, you will get the package with Install.ps1 in the tools directory:
Related
I have a Class Library (net47) project and I'd like to pack into a nuget my dll and several files of static content (js, css, images...). I want to use this dll and the content from the consumer projects. These projects will be MVC PackageReference projects. In these projects the local static files are in the wwwroot folder.
I have tried this: NuGet ContentFiles Demystified but I get my js and css files referenced (they aren't copied to my project content).
In my nuspec I've tried with all build options: EmbeddedResource, Content, None and Compile, but these references are imported always in Compile mode. So I get a compile error when I start debugging.
I know this was possible with Package.config projects and it's very simple but all my consumer projects will be PackageReference.
This is my nuspec
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MyProject</id>
<version>1.0.0</version>
<authors>My</authors>
<owners>My</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>LVP</description>
<copyright>Copyright 2018</copyright>
<tags>Tag1 Tag2</tags>
<contentFiles>
<files include="any/any/bd.js" buildAction="content" flatten="true" copyToOutput="false"/>
</contentFiles>
</metadata>
<files>
<file src="contentFiles/any/any/bd.js" target="contentFiles/any/any/bd.js" />
</files>
</package>
I pack my nuget with this powershell command:
nuget pack MyProject.nuspec
Although I have also tried with the csproj:
nuget pack MyProject.csproj
And my source folder structure is this:
C:\...[projectPath]...\contentFiles\any\any\bd.js
Installation is ignoring my build action.
Why is always trying to compile my content files? Is there a better way to add static content to the consumer project?
Installation is ignoring my build action. Why is always trying to compile my content files? Is there a better way to add static content to the consumer project?
To answer your previous question Packing files on nuget, I have created a sample nuget package and set the build action to content for the content files, after install that nuget package, the build action would be set content:
Then I checked your .nuspec file, found it should be correct. So the issue is not related to your .nuspec file.
Besides, in the above image, you will notice that the path of the content file is nuget local cache:
C:\Users\<UserName>\.nuget\packages\
NuGet will first extract the nuget package from the local cache when install the nuget package to avoid downloading packages that are already on the computer. In other wards, although we have updated the nuget package in the local, nuget will detect the local cache first, if it found the same package in the cache, nuget will install it from cache rather than local feed.
To resolve this issue, please try to remove your nuget package in the local cache before installing the updated nuget package. Generally, when we package the same package again, wed better change the package version in the.nuspec` file so nuget local cache will not catch them.
Update for comment:
I've tried increasing the version number and deleting the nuget cache and the problem persists. My build action is always set to "C# Compiler". I just tried changing the name of the js file and the project imports the new name so I do not think it's a cache problem
After test your nuget package, I found the reason why you get that issue, we should keep the path the src and target paths are the same in the .nuspec file. Since you want set content file to the wwwroot folder, you should set the file in the wwwroot folder, then pack the .nuspec:
<contentFiles>
<files include="any/any/wwwroot/css/bd.css" buildAction="Content" copyToOutput="false" flatten="true" />
<files include="any/any/wwwroot/js/bd.js" buildAction="Content" copyToOutput="false" flatten="true" />
</contentFiles>
Following in my .nuspec scripts(Not need content node):
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>BancaDigitalViewProvider</id>
<version>1.0.37</version>
<authors>Ibercaja</authors>
<owners>Ibercaja</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Login View Provider</description>
<copyright>Copyright 2018</copyright>
<tags>Banca Digital View Provider</tags>
<dependencies />
<contentFiles>
<files include="any/any/wwwroot/css/bd.css" buildAction="Content" copyToOutput="false" flatten="true" />
<files include="any/any/wwwroot/js/bd.js" buildAction="Content" copyToOutput="false" flatten="true" />
</contentFiles>
</metadata>
<files>
<file src="contentFiles/any/any/wwwroot/css/bd.css" target="contentFiles/any/any/wwwroot/css/bd.css" />
<file src="contentFiles/any/any/wwwroot/js/bd.js" target="contentFiles/any/any/wwwroot/js/bd.js" />
<file src="bin\debug\BancaDigitalViewProvider.dll" target="lib\net47\BancaDigitalViewProvider.dll" />
</files>
</package>
This is nuget package:
https://1drv.ms/u/s!Ai1sp_yvodHfhTk5xutPpaBZLC-A
You can download it and test.
Then install it to the ASP.NET core MVC project:
Hope this helps.
I have this nuspec file:
<?xml version="1.0"?>
<package >
<metadata>
<id>My.Package</id>
<version>1.0.1.7</version>
<title>My Package</title>
<authors>My name</authors>
<owners>Mu author</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>My description</description>
<releaseNotes>Release note</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>tag1 tag2</tags>
<contentFiles>
<files include="myFile.config" copyToOutput="true" />
</contentFiles>
</metadata>
<files>
<file src="myFile.config" target=""/>
</files>
</package>
When I pack this nuspec file, my nupkg file is created and in the NuGet Package Explorer I see that myFile.config is included in my package. All well so far.
But, then, when I install this package, the dll is added to references, but myFile.config is not added to the solution.
Things I've tried without success:
- View the folder on Disk to see if myFile.config is created (not there)
- <file src="myFile.config" target="."/>
- <file src="myFile.config" target=".\"/>
I also want the file to set Copy to Output Directory: Copy always.
What am I missing here?
PS: I am working on a private nuget server.
The target needs to be content since files of the nugpkg's content subdirectory are copied to the consuming project.
Note that this only works for projects using the packages.config style of referencing NuGet packages. For PackageReference (available in VS 2017, default for .NET Core / ASP.NET Core / .NET Standard projects), there is a new contentFiles feature that includes files logically in the build process.
See NuGet's documentation on including content files for more information.
I'm trying to create a nuget package for a specific build configuration. Let's use Debug as an example. I run the command:
nuget pack path_to_my.nuspec -Properties "Configuration=Debug;"-Verbosity Detailed
It throws me the following error:
Attempting to build package from 'path_to_my.nuspec'.
System.IO.FileNotFoundException: File not found: 'bin\Release\mydll.dll'.
As you can see, it tries to get the dll from bin\Release, and not bin\Debug.
Is it possible to tell nuget to use a different Configuration than Release, or use another path?
It would be necessary to check your nuspec file just in case you have hardcoded the Release path to bin\Release\mydll.dll, which is seems it's the case.
A valid nuspec file would have references to the dll without specifying the environment. Use wildcard to allow for any environment. For example:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MyProject</id>
<authors>iberodev</authors>
<version>1.0.0</version>
<projectUrl>https://www.diegodrivendesign.com/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Sample</description>
</metadata>
<files>
<file src="bin\*\netstandard2.0/ProjectOne.dll" target="lib\netstandard2.0" />
<file src="bin\*\netstandard2.0/ProjectOne.pdb" target="lib\netstandard2.0" />
<file src="bin\*\netstandard2.0/ProjectTwo.pdb" target="lib\netstandard2.0" />
<file src="bin\*\netstandard2.0/ProjectTwo.pdb" target="lib\netstandard2.0" />
</files>
</package>
then you run the nuget pack command to reference your nuspec. Make sure you have compiled the code for the proper environment so that the dll that the nuspec references are available (e.g: dotnet build --configuration Debug)
nuget pack ./*NuGet/*.nuspec -Version 1.0.0 -OutputDirectory foo -Prop Configuration=Debug -Verbosity detailed
I have a managed project that uses a C-style native DLL through P/Invoke.
What is the correct way to package the native DLL so it can be added as a NuGet package to the managed project, and have the DLL be copied automatically to the output folder?
I have currently created a package using CoApp for the native DLL but i can't use it from the managed project; I get the following error when trying to add the package:
Could not install package 'foo.redist 1.0.0'. You are trying to
install this package into a project that targets
'.NETFramework,Version=v4.5.1', but the package does not contain any
assembly references or content files that are compatible with that
framework. For more information, contact the package author.
Currently i only have these "pivots" in the autopkg file:
[Win32,dynamic,release] {
bin: release\foo.dll;
}
[Win32,dynamic,debug] {
bin: debug\foo.dll;
}
... do i need to add something else?
I'm in a similar situation. I opted not to use CoApp for this project, but to create a fresh nuspec/.targets file combination instead.
Inside the nuspec file I use a <files> element to list my native dlls.
In the .targets file you have access to the msbuild Condition attribute, which allows basic Configuration pivoting. In our case we always deploy 64 bit binaries, so the Platform pivot is not needed, but you could also add it if needed.
I get warnings when running nuget pack since the binaries are not inside lib, but it works fine otherwise.
Steps:
run nuget spec in the folder that contains your vcxproj
create a .build folder, in that folder create an empty mydll.targets file (match the nuspec filename)
manually populate the files similarly to the examples below;
Example mydll.nuspec:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
...your metadata here
</metadata>
<files>
<file src="x64\Release\my.dll" target="x64\Release\my.dll" />
<file src="x64\Debug\my.dll" target="x64\Debug\my.dll" />
</files>
</package>
Example mydll.targets:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)\..\x64\Release\my.dll" Condition="'$(Configuration)'=='Release'">
<Link>my.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)\..\x64\Debug\my.dll" Condition="'$(Configuration)'=='Debug'">
<Link>my.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
I'm using Octopack / Nuspec file to build my nuget package.
I would like to exclude certain folders which exist in the project. e.g. the "obj" file. I've been trying to get the exclude tag to work, but haven't had any luck. The nuget file builds, but the folder is still there.
Sadly, all the examples on the net specific file types and not folder.
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Foo</id>
<title>Foo</title>
<version>$version$</version>
<authors>NA</authors>
<owners>NA</owners>
<licenseUrl>http://Foo</licenseUrl>
<projectUrl>http://Foo</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Foo</description>
<releaseNotes>NA</releaseNotes>
</metadata>
<files>
<file src="obj\**\*.*" exclude="*.*" />
</files>
</package>
I needed to create a WebApplication, but deploy it as a standard ASP.NET website using "CodeFile" attributes.
This was basically to update a page in the standard ADFS login site.
<files>
<file src="**" exclude="**\*.dll;**\*.designer.cs;**\*.csproj;**\*.pdb;**\*.user;**\*.vspscc;bin\*.cs;bin\*.aspx;bin\*.config;bin\*.asax;bin\*.pubxml" />
</files>
To directly answer the posters question, if you want to exclude only the obj folder from a Nuget package use the following in your nuspec xml
<files>
<file src="*\**" target="\" exclude="obj\**\*.*"/>
</files>
Depending on the project you are building, you shouldn't need to exclude anything.
If you are building a Windows Service/Console application, OctoPack should only package your bin\release directory.
If you are building a web application, you should use a 'publish' command to have MSBuild sent the binaries and content files to a temporary folder, and OctoPack will package that. This way your obj folders and C# files won't be packaged.
For information on how to do this, please see the section on Web Application Publishing at:
http://octopusdeploy.com/documentation/packaging/octopack