Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create nuget package fails with 'Path is not of a legal form'

Tags:

c#

nuget

msbuild

In a post build step we create nuget packages. For some reasons this always fails on my machine, while it works on other developers machines.

The command executed is:

nuget.exe  pack "$(ProjectPath)" -Properties Configuration=$(ConfigurationName) -OutputDir "$(ProjectDir)..\Apps"

The output i get is:

Packing files from ''.
Using 'Organisation.AppName.Modules.Kcs.nuspec' for metadata.
The path is not of a legal form.

For other developers the first line contains the directory. What can be the reason it is working differently on my box? Are there options i can set to change this behavior?

Edit: I downloaded the nuget source and found the point things start to go wrong. With a small test program i can simulate it:

using System;
using Microsoft.Build.Evaluation;

namespace CheckTarget
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("usage: CheckTarget projectfile.csproj");
                Console.WriteLine();
                return;
             }

             string path = args[0];
             var project = new Project(path);


             Console.WriteLine("TargetDir = {0}", project.GetProperty("TargetDir") != null ? project.GetProperty("TargetDir").EvaluatedValue : string.Empty);
             Console.WriteLine("TargetPath = {0}", project.GetProperty("TargetPath").EvaluatedValue);
             Console.ReadKey();
         }
     }
}

On my machine the targetdir is null, on another machine the targetdir points to valid directory.

like image 489
W van Noort Avatar asked Jun 12 '13 13:06

W van Noort


People also ask

How do I fix NuGet recovery failed?

Quick solution for Visual Studio usersSelect the Tools > NuGet Package Manager > Package Manager Settings menu command. Set both options under Package Restore. Select OK. Build your project again.

Where is the path of NuGet exe?

Install the official nuget.exe in your PC. Create a Symbolic Link here: %localappdata%\microsoft\winget\links. Make the nuget.exe globally available for your user to call it from anywhere, since the aforementioned directory should be present in your user's PATH variable.


1 Answers

Use property Platform to -Properties parameter in nuget program

-Properties Platform=$(Platform)

where $(Platform) is one of your project platform (defined in csproj file, typically x86, 'Any CPU', ..).

ie in your case, run something like:

nuget.exe pack "$(ProjectPath)" -Properties Configuration="$(ConfigurationName)" Platform="$(Platform)" -OutputDir "$(ProjectDir)..\Apps"
like image 83
honzakuzel1989 Avatar answered Oct 03 '22 15:10

honzakuzel1989