Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An update for Visual Studio Packaging docs #830

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions docs/using/visual-studio-packaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ Squirrel packaging can be easily integrated directly into your build process usi
The first step is to define a build target in your `.csproj` file.

```xml
<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Release'"> <GetAssemblyIdentity AssemblyFiles="$(TargetPath)"> <Output TaskParameter="Assemblies" ItemName="myAssemblyInfo"/> </GetAssemblyIdentity> <Exec Command="nuget pack MyApp.nuspec -Version %(myAssemblyInfo.Version) -Properties Configuration=Release -OutputDirectory $(OutDir) -BasePath $(OutDir)" /> <Exec Command="squirrel --releasify $(OutDir)MyApp.%(myAssemblyInfo.Version).nupkg" /></Target>
<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Release'">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="myAssemblyInfo"/>
</GetAssemblyIdentity>
<Exec Command="nuget pack $(MSBuildProjectName).nuspec -Version %(myAssemblyInfo.Version) -Properties Configuration=Release -OutputDirectory $(OutDir) -BasePath $(OutDir)" />
<Exec Command="squirrel --releasify $(OutDir)$(MSBuildProjectName).%(myAssemblyInfo.Version).nupkg" />
</Target>
```

This will generate a NuGet package from .nuspec file setting version from AssemblyInfo.cs and place it in OutDir (by default bin\Release). Then it will generate release files from it.
Expand All @@ -20,23 +26,37 @@ This will generate a NuGet package from .nuspec file setting version from Assemb
Here is an example `MyApp.nuspec` file for the above build target example.

```xml
<?xml version="1.0" encoding="utf-8"?><package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <metadata> <id>MyApp</id> <!-- version will be replaced by MSBuild --> <version>0.0.0.0</version> <title>title</title> <authors>authors</authors> <description>description</description> <requireLicenseAcceptance>false</requireLicenseAcceptance> <copyright>Copyright 2016</copyright> <dependencies /> </metadata> <files> <file src="*.*" target="lib\net45\" exclude="*.pdb;*.nupkg;*.vshost.*"/> </files></package>
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MyApp</id>
<!-- version will be replaced by MSBuild -->
<version>0.0.0.0</version>
<title>title</title>
<authors>authors</authors>
<description>description</description>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<copyright>Copyright 2016</copyright>
<dependencies />
</metadata>
<files>
<file src="*.*" target="lib\net45\" exclude="*.pdb;*.nupkg;*.vshost.*"/>
</files>
</package>
```

## Additional Notes

Please be aware of the following when using this solution:
We use `nuget pack MyApp.nuspec -Version ...` instead of usual `nuget pack MyApp.csproj` to prevent it from including project dependencies into the package.

* Solution needs to have nuget.exe available which can be accomplished by installing `NuGet.CommandLine` package in your solution.
## Additional Notes

~~~pm
PM> Install-Package NuGet.CommandLine
~~~
* It suffers from a bug when sometimes NuGet packages are not loaded properly and throws nuget/squirrel is not recogized (9009) errors.
**Tip:** In this case you may simply need to restart Visual Studio so the Package Manager Console will have loaded all the package tools
* If you get the following error you may need add the full path to squirrel.exe in the build target `Exec Command` call. `'squirrel' is not recognized as an internal or external command`
MSBuild needs to be able to find `nuget.exe` and `squirrel.exe` which can be accomplished in one of the following ways:
* Using full paths to exe files in your `Exec` commands
* Including paths to executables in your system PATH variable
* Visual Studio package manager can automatically find tool executables from installed NuGet packages and include them into local environment path. To do this:
* Install `NuGet.CommandLine` package in your solution to get nuget.exe: `PM> Install-Package NuGet.CommandLine`
* Open Package Manager Console window to scan solution for executable tools. You have to open this window each time you restart VS. Sometimes VS forgets paths to tools after some time due to a bug - in that case you need to reopen your solutuon.

**Source:** [Issue #630](https://github.com/Squirrel/Squirrel.Windows/issues/630)
If you get Error 9009: `'squirrel/nuget' is not recognized as an internal or external command` that means MSBuild can't find nuget.exe or squirrel.exe.

---
| Return: [Packaging Tools](packaging-tools.md) |
Expand Down