DotNet Pack Not Doing Anything - asp.net

I am trying to create a nuget package for my web application but it is not producing any .nupkg outputs. I am using Visual Studio 2017 15.3.0.
To create the project I do the following:
File - New - Project,
Visual C# - Web,
Asp.Net Core Web Application,
Web Application
Then I go to a command prompt in the directory with the csproj file in and type:
"Dotnet Pack"
I get only the following output:
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
But no nuget packages are created. I am expecting something like:
Producing Nuget Package "App.1.0.0" for App
Do I need to do anything else eg to the csproj file ?

Web applications are not packable by default. To change this, modify your csproj file to include this property:
<PropertyGroup>
<IsPackable>true</IsPackable>
</PropertyGroup>
Note that as of now (2017) there isn't a good story for "library web projects" or web project packages that work for all scenarios you would want to use a NuGet package for. But this property will at least unblock producing a package.

I had the same issue with VS2022, looked at the documentation and noticed they "silently deprecated" the command.
You now should add the following in your .csproj file:
You then generate a package and copy it to the "right" folder by calling
dotnet msbuild -t:pack -property:Configuration=Release "ProjectFile.csproj"
Have a look at the link, the title is a bit confusing but there seemed to have been a change after With MSBuild 15.1+

Related

Different Newtonsoft.Json.dll dotnet publish vs publish with Visual Studio

I have a .NET Core Web Application with target framework .netcoreapp2.0.
If i publish my application via Visual Studio (folder profile) I get a different Newtonsoft.Json.dll then with the command dotnet publish --configuration Release --output D:/publish/Frontend /property:PublishWithAspNetCoreTargetManifest=false
VS publish version:
dotnet publish version:
The created file AutomaticConfirmationWebfrontend.deps.json has always this dependency:
"runtime": {
"lib/netstandard1.3/Newtonsoft.Json.dll": {
"assemblyVersion": "10.0.0.0",
"fileVersion": "10.0.1.20720"
}
}
This results in a problem for my CI/CD process where I publish my app with the command dotnet publish. If I open the website I get an error message that the assembly Newtonsoft.JSON 10.0.0.0 could not be found. If i copy manually the DLL with version 10.0.0.0 to the application folder it works! Debugging my application locally works also fine!
I have no Newtonsoft NuGet package installed. I think I am using the built in package from .NET Core.
In my Startup.cs I have the following line of code:
services.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
I need this for lowercase JSON objects. I have imported this namespace:
using Newtonsoft.Json.Serialization
Anybody an idea what I'm doing wrong or how to fix this?
I did 3 steps:
Upgraded to netcoreapp3.1
Removed all nuget packages from C:\Users\******\.nuget\packages
Installed the latest MSBuild installer
Late answer but it may help someone in future. Within the solution some other (other project) NuGet package also depending Newtonsoft.Json.dll. Check all your NuGet package dependencies especially Testing projects which may be mapped with low version Newtonsoft.Json.dll. (Refer below pic).
If that is the problem, then you can map .csproj file in your publish command like below,
dotnet publish src/myproject.csproj --configuration Release --output D:/publish/Frontend /property:PublishWithAspNetCoreTargetManifest=false

How to pack .NET Core projects recursively without running pack on the entire solution?

I have a solution of a hundred plus .NET Core projects. Not all of them needs to be packed, but only those which are transitive dependencies of a few special projects.
However, when I run dotnet pack it attempts to pack all kinds of projects that it should not and there are errors here and there. I would like instead to run pack on the special projects only in a recursive fashion, so that only them and their transitive dependencies (project references, of course) are packed.
I figured I can implement it by scripting around the dotnet list reference command, but it does not sound right. There must be a better way to do it.
EDIT 1
The solution must work on the command line where we have dotnet and msbuild and possibly nuget, but no VS IDE.
You can modify your project settings to generate *.nupkg file during dotnet build, without explicit dotnet pack call. And as soon as dependencies get builded automatically when "parent" project builds - you will receive nuget packages prepared for all dependencies too when you run dotnet build for "parent" project only.
For each project that should produce nuget package add this lines into csproj file:
<PropertyGroup>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
Or, instead, you may enable checkbox "Generate NuGet package on build" from Visual Studio, in project properties ("Package" tab) - this will add same line into project file.

Cannot publish a self-contained dotnet-core application due to NU1100

I have ported a .net application to .netcore and want to publish it as a self-contained application. Unfortunately, this does not work:
dotnet publish -r win-x64
Microsoft (R) Build Engine version 16.4.0+e901037fe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
<Path>\IPLauncher.csproj : error NU1100: Unable to resolve 'Microsoft.NETCore.App.Runtime.win-x64 (= 3.1.2)' for '.NETCoreApp,Version=v3.1'.
<Path>\IPLauncher.csproj : error NU1100: Unable to resolve 'Microsoft.WindowsDesktop.App.Runtime.win-x64 (= 3.1.2)' for '.NETCoreApp,Version=v3.1'.
<Path>\IPLauncher.csproj : error NU1100: Unable to resolve 'Microsoft.AspNetCore.App.Runtime.win-x64 (= 3.1.2)' for '.NETCoreApp,Version=v3.1'.
Restore failed in 179,65 ms for <Path>\IPLauncher.csproj.
In case it is important, my csproj-file looks like this:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
</Project>
Edited to add: The weirdest part is that my colleague can publish a self-contained exe for the same project with identical configuration - so it seems to be some problem with my configuration.
It seems like nuget restore command for your application can't restore some packages.
There are many reasons for that, but you can do basic research for determine why it's heppens. Here some tips:
Clear all NuGet caches dotnet nuget locals all --clear
Check if NuGet packages you trying to restore accessible from nuget.org website. Official nuget package manager website has different API's (v2/v3) so you must check you use latest version of API.
If you use NuGet package not from official portal - verify that NuGet server you use for restoring nuget packages is accessible.
These settings placed in default nuget.config file here: %appdata%\NuGet\NuGet.config
Note that if you using custom nuget.config for your project/solution it's overrides default nuget settings. This file can contains some settings that breaks restore command. So check it out first.

MSBuild doesn't create a Web Deploy Package from command line with VS2017 PublishProfile

I use Visual Studio 2017 and have created some publish profiles. One of these is a CustomProfile1 Web Deploy Package, it works like charm when pressing Publish and i get:
- BuildTest.deploy.cmd
- BuildTest.deploy-readme.txt
- BuildTest.SetParameters.xml
- BuildTest.SourceManifest.xml
- BuildTest.zip
I have tried numerous experiments with msbuild but does not work to generate the files from command line
msbuild Buildtest.sln /p:DeployOnBuild=true /p:PublishProfile=CustomProfile1.pubxml
bin and obj folders are getting filled, but apprently CustomProfile1 is not triggered from command line shot?
msbuild -version
Microsoft (R) Build Engine version 4.6.1586.0
[Microsoft .NET Framework, version 4.0.30319.42000]
The command is probably confused as to which configuration you want to build,try adding
/p:configuration=Debug
you can also put Staging or Release depending on which configuration you want.

Change .NET Core application generated exe description

I have created a .NET Core application. When I do:
dotnet publish -r win81-x64
All files needed to execution are deployed in the following folder:
\bin\Debug\netcoreapp1.1\win81-x64\publish
There, among all the files I have a dll file with the name Example.dll and the exe file named Example.exe. Now, my problem is when I execute the exe, in the task manager the application description says:
dotnet
I would like to change that to Example, for that I tried to edit my csproj to contain the following:
<PropertyGroup>
<OutputType>Exe</OutputType>
<Version>1.0.0.0</Version>
<Description>Example</Description>
<TargetFramework>netcoreapp1.1</TargetFramework>
<RuntimeIdentifiers>win81-x64</RuntimeIdentifiers>
<Satellite_Description>Example</Satellite_Description>
</PropertyGroup>
But it doesn't seems to have any affect in the generated exe file, only ind the dll. How can I change the exe description?
Currently this is not possible in the build process.
Unlike classic .NET projects, this .exe file isn't actually compiled but is a pre-built binary (dotnet.exe, in 2.0 apphost.exe) acquired via a NuGet package and copied/renamed to the publish output.
There is an issue on GitHub about changing the description after being launched, but at the time of writing it is not assigned to a milestone of an expected release.
There is known issue in populating assemblyino manifest into EXE file. Looks like will be supported in .net core 3.0 release.
see: https://github.com/dotnet/sdk/issues/1899

Resources