Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The following code comes from a package called CodeAssassin.WixWebProjectReferences. It adds <strong>and removes</strong> the following import-tag to the project file upon install and uninstall. The package does not require any dependencies.</p> <pre class="lang-xml prettyprint-override"><code>&lt;Import Project="..\packages\CodeAssassin.WixWebProjectReferences.1.0\tools\CodeAssassin.WixWebProjectReferences.targets" /&gt; </code></pre> <p>Download the package and open it using <a href="http://nuget.codeplex.com/releases/view/59864">NuGetPackageExplorer</a> to se how it's done. </p> <p>Below is the code from install.ps1 and uninstall.ps1 (they are only executed if the content folder of the NuGet-package is non-empty).</p> <p>(I couldn't find any powershell-highlighting so I used php instead and it's not perfect.)</p> <h2>install.ps1</h2> <pre class="lang-php prettyprint-override"><code>param ( $InstallPath, $ToolsPath, $Package, $Project ) $TargetsFile = 'CodeAssassin.WixWebProjectReferences.targets' $TargetsPath = $ToolsPath | Join-Path -ChildPath $TargetsFile Add-Type -AssemblyName 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' $MSBProject = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($Project.FullName) | Select-Object -First 1 $ProjectUri = New-Object -TypeName Uri -ArgumentList "file://$($Project.FullName)" $TargetUri = New-Object -TypeName Uri -ArgumentList "file://$TargetsPath" $RelativePath = $ProjectUri.MakeRelativeUri($TargetUri) -replace '/','\' $ExistingImports = $MSBProject.Xml.Imports | Where-Object { $_.Project -like "*\$TargetsFile" } if ($ExistingImports) { $ExistingImports | ForEach-Object { $MSBProject.Xml.RemoveChild($_) | Out-Null } } $MSBProject.Xml.AddImport($RelativePath) | Out-Null $Project.Save() </code></pre> <h2>uninstall.ps1</h2> <pre class="lang-php prettyprint-override"><code>param ( $InstallPath, $ToolsPath, $Package, $Project ) $TargetsFile = 'CodeAssassin.WixWebProjectReferences.targets' Add-Type -AssemblyName 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' $MSBProject = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($Project.FullName) | Select-Object -First 1 $ExistingImports = $MSBProject.Xml.Imports | Where-Object { $_.Project -like "*\$TargetsFile" } if ($ExistingImports) { $ExistingImports | ForEach-Object { $MSBProject.Xml.RemoveChild($_) | Out-Null } $Project.Save() } </code></pre> <h2>Sample targets-file that copies some files to the output path</h2> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"&gt; &lt;ItemGroup&gt; &lt;Files Include="..\packages\Insert_Path_To_Your_Package_Folder_Here\bin\*" /&gt; &lt;/ItemGroup&gt; &lt;Target Name="Insert_Name_of_Your_Target_Here" AfterTargets="AfterBuild"&gt; &lt;Copy SourceFiles="@(Files)" DestinationFolder="$(TargetDir)\bin\" SkipUnchangedFiles="true" /&gt; &lt;/Target&gt; &lt;/Project&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload