Tom Regan
Tom Regan

Reputation: 3851

devenv.exe creates empty bin folder with no Nuget package

I'm using Visual Studio 2022 to build a .Net Core 7 dll. The solution contains a single project. When I rebuild the solution I want to create a Nuget package. This works fine when I select "Build - Rebuild solution" from inside visual studio.

My *.csproj file looks like this:

  <PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Platforms>x64</Platforms>
<Version>2.0.0</Version>
<DebugType>embedded</DebugType>
<EmbedAllSources>true</EmbedAllSources>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

When I rebuild the solution it creates the file "bin\x64\Release[My Library Name.Version Number].nupkg" and the folder "bin\x64\Release\net7.0" with the dll.

I want to do the same thing from the command line. I'm using the instructions from https://learn.microsoft.com/en-us/visualstudio/ide/reference/build-devenv-exe?view=vs-2022.. My batch file looks like this:

"C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\devenv.exe" "[path to my solution file].sln" /rebuild Release /project "[folder of my project file].csproj" /projectconfig Release 

This runs successfully, and creates both the "obj" and "bin" folders, but no Nuget package is created and the "bin" folder is empty. What am I missing?

Upvotes: 0

Views: 241

Answers (1)

Tom Regan
Tom Regan

Reputation: 3851

@Hans_Passant gave correct advice, the *.bat file is two lines (first line restores nuget packages that the library consumes, 2nd line creates the library + nuget package):

"C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe" "[path to my solution file].sln" /t:restore /p:RestorePackagesConfig=true 
"C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe" "[path to my solution file].sln" /p:Configuration=Release /p:Platform=x64

Upvotes: 0

Related Questions