Tino Hager
Tino Hager

Reputation: 1079

Add install.ps1 on Class Library (.NET Standard) Project

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".

Upvotes: 2

Views: 951

Answers (2)

Robba
Robba

Reputation: 8324

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

Upvotes: 3

Leo Liu
Leo Liu

Reputation: 76760

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:

enter image description here

Upvotes: 0

Related Questions