Search code examples
c#nugetunsafepack

Getting error when using nuget pack for a solution with some unsafe code


I am currently trying to pack a nuget package for solution with some unsafe code. It's running fine with MSBuild because I am able to give it the following parameter: /p:AllowUnsafeBlocks=true

I have tried several way to give the same parameter to my nuget.exe pack command.

".\.nuget\nuget.exe" pack "My.csproj" -Build -IncludeReferencedProjects -Version 02.06.5 -verbosity detailed -suffix UAT -Properties "Configuration=Release AllowUnsafeBlocks=true" 


".\.nuget\nuget.exe" pack "My.csproj" -Build -IncludeReferencedProjects -Version 02.06.5 -verbosity detailed -suffix UAT -Properties "Configuration=Release" "AllowUnsafeBlocks=true"

I am getting the following error:

error CS0227: Unsafe code may only appear if compiling with /unsafe

EDIT: It's also running fine from VS becase the solution is well setup :)


Solution

  • the solution is really simple.... Add ';' between each -Properties parameters.

    ".\.nuget\nuget.exe" pack "My.csproj" -Build -IncludeReferencedProjects -Version 02.06.5 -verbosity detailed -suffix UAT -Properties "Configuration=Release;AllowUnsafeBlocks=true"