Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use environment variable in NuGet config?

Is there a way to use an environment variable in NuGet.Config file?

Currently I am constrained to using relative path, as follows:

<configuration>
  <config>       
    <add key="repositoryPath" value="..\..\teampackages" />
  </config>
</configuration>

But would be really handy to have an environment variable with absolute path instead.

like image 892
Andriy Drozdyuk Avatar asked May 31 '13 15:05

Andriy Drozdyuk


People also ask

How do you set the local path of NuGet EXE to your path environment variable?

Click “Advanced System Settings” then click the “Environment Variables” button located within the Advanced tab. From here double-click the PATH variable in the top panel and create a new entry by adding the path to the directory that contains your NuGet.exe file (in this instance it's C:/NuGet/).

How do I change the source of a NuGet package?

To manage your package sources, select the Settings icon or select Tools > Options. In the Options window, expand the NuGet Package Manager node and select Package Sources. To add a source, select +, edit the Name, enter the URL or path in Source, and then select Update.

Where is NuGet NuGet Appdata config?

Abstract. The NuGet Visual Studio extension, the NuGet Package Manager Console, and the NuGet command-line tool all make use of the NuGet configuration file, which by default is located under %AppData%\NuGet\NuGet.


1 Answers

If you run nuget pack MyProject.csproj on a project with a corresponding MyProject.nuspec file in the same directory, NuGet will make the MSBuild properties available as tokens in the format $Property$, where Property is the name of the MSBuild property. For example:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>$description$</description>
    <copyright>Copyright 2013</copyright>
  </metadata>
  <files>
    <file src="$OutputPath$MyProject.pdb" target="lib\net40"/>
  </files>
</package>

In this example $id$, $version$, $title$, $author$ and $description$ are special values provided by NuGet itself based on the project file and AssemblyVersion attribute (normally found in AssemblyInfo.cs). However, $OutputPath$ is an MSBuild property defined in the common targets. You could also use $MSBuildProjectDirectory$ or any other standard property.

More info here ("Replacement Tokens" section):

NuSpec Reference

like image 159
Jesse Sweetland Avatar answered Sep 19 '22 09:09

Jesse Sweetland