Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet Pack -Build does not seem to understand c# 6.0

Tags:

c#

nuget

c#-6.0

I have just went through one of my projects and used a bunch of the new c# 6 features like the null propagation operator handler?.Invoke(null, e), which builds in Visual Studio. However, when I run my script to publish out the NuGet packages, I get compilation errors saying:

EventName.cs(14,66): error CS1056: Unexpected character '$'
EventName.cs(69,68): error CS1519: Invalid token '=' in class, struct, or interface member declaration
EventName.cs(69,74): error CS1520: Method must have a return type

It would appear NuGet is using an older version of the compiler, but I was wondering if anyone knew a work around or configuration that could be set to resolve the issue.

like image 382
Gent Avatar asked May 16 '15 02:05

Gent


People also ask

Are NuGet packages case sensitive?

Setting names are case-insensitive, and values can use environment variables. Add a nuget. config file in the root of your project repository.

Is NuGet Package same as DLL?

Put simply, a NuGet package is a single ZIP file with the . nupkg extension that contains compiled code (DLLs), other files related to that code, and a descriptive manifest that includes information like the package's version number.

Where does NuGet find config file?

nuget/NuGet folder. These other tools look for the user config file under the ~/. config/NuGet folder: Mono.

How use NuGet C#?

Step 1 - Select Tools > NuGet Package Manager > Package Manager Console. It will open a console in the bottom of the window. Step 2 - Select your project and execute the command to install the package. If it's a valid command, then the package will be installed to your project.


1 Answers

Looks like you have also found this bug in the Nuget which is still not resolved: https://github.com/NuGet/Home/issues/1107

You can use the following workaround:

  1. Modify the script to build your project using correct version of MSBuild - just call MSBuild.exe yourself, supply the path to the csproj or sln file and build your project in a correct configuration yourself.

  2. Create a nuspec file that describes your package (https://docs.nuget.org/create/nuspec-reference). You can use the Nuget Package Explorer app. Use DLLs produced in step 1.

  3. Use nuget pack mypackage.nuspec to build the package.

like image 170
Tomáš Herceg Avatar answered Sep 24 '22 08:09

Tomáš Herceg