VS2017 set "Build Action" to "Content" in nuget package

I am creating nuget packages in gitlab with the following command line.

 nuget pack -Prop Configuration=Release -OutputDirectory nuget %REPONAME%\%APPNAME%\%APPNAME%.csproj 

If I declare Build Action - Content and Copy To Output Directory - Always , it is not applied in the nuget package or, rather, when installing it.

I am a little confused by the answers here: Set content files to "copy local: always" in nuget package

I do not have a * .nuspec file. It is automatically generated by the command above.




  • I declared the Install.ps1 file in my solution in tools/*
  • I want to automatically include the tools folder with Install.ps1 script in the nuget package that this script is called upon installation



Install.ps1 script

 param($installPath, $toolsPath, $package, $project) $configItem = $project.ProjectItems.Item("snap7.dll") # set 'Copy To Output Directory' to 'Always' # 0 = Never # 1 = Always # 2 = PreserveNewestFile $copyToOutput = $configItem.Properties.Item("CopyToOutputDirectory") $copyToOutput.Value = 1 # set 'Build Action' to 'Content' # 0 = None # 1 = Compile # 2 = Content # 3 = EmbeddedResource $buildAction = $configItem.Properties.Item("BuildAction") $buildAction.Value = 2 
+2
visual-studio nuget visual-studio-2017 nuget-package
Nov 02 '17 at 12:14
source share
2 answers

To automatically add files / folders to the nuget package, I wrote a small tool called NuGetLib .

Global variables are automatically set by the installer.

In my .gitlab-ci.yml only these 4 lines are needed to build the nuget package with all the dependencies and the tool folder:

 # create output directory - mkdir nuget # create nuget package - nuget pack -Prop Configuration=Release -OutputDirectory nuget %REPONAME%\%APPNAME%\%APPNAME%.csproj # Add tools folder - nugetlib add -t nuget -f .\%REPONAME%\%APPNAME%\tools # deploy package to local repo - xcopy /s /y /i nuget %NUGET_PATH% 

You can download it here: Download

Readme

NuGetLib

Command line tool for additional operations with nuget packages

It is written in C # and needs .Net-Framework 4.6.1 to run. On Linux, it must also be executed using Mono (not yet tested).

Using

nugetlib about

 nugetlib about 

Displays current version information.

nugetlib add

 nugetlib add [-t <path to the target file or folder>] [-f <path to the file/folder to add>] 

Adds a file or folder to an existing nuget package file ( .nupkg ). If you send the folder as a target, a new * is automatically created . Nupkg file.

NuGetLib uses 7zip to manage packages. The -f is passed directly to the 7zip library:

add command

Adds files to the archive.

Examples

nugetlib add -t example.nupkg subdir\

Adds all files and subfolders from the subdir folder to the example.nupkg archive. File names in the archive will contain the subdir \ prefix.

nugetlib add -t example.nupkg .\subdir\*

Adds all files and subfolders from the subdir folder to the example.nupkg archive. File names in the archive will not contain the subdir \ prefix.

nugetlib add -t example.nupkg .\subdir\tools\

adds the tools folder to the example.nupkg archive. File names in the archive will not contain the subdir \ prefix.

cd /D c:\dir1\

nugetlib add -t example.nupkg dir2\dir3\

The file names in the example.nupkg archive will contain dir2 \ dir3 \ prefix, but they will not contain c: \ dir1 \ prefix.

0
Nov 06 '17 at 10:27
source share
β€” -

You need to add install.ps1 file to your nuget package.

After using the nuget pack command that you provided in your original message, it will create the package in the nuget folder.

Then open this NuGet Package Explorer package and add the tool folder through CONTENT β†’ Add β†’ Tool Folder in the NuGet Package Explorer menu. And then add the install.ps1 file to the tools folder.

Now that the package is installed in the project, it will call the install.ps1 file to set the Copy Copy to Output Directory property as Copy Always.

+1
Nov 03 '17 at 2:50
source share



All Articles