I use Visual Studio 2017, MSBuild version 15.4.8.50001.
I want to create a .nupkg file by reading directly from my .csproj file. Following the instructions here, I updated the first PropertyGroup in my .csproj file to this:
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{24BAFE05-8B92-4EAA-8790-03C0768ACC57}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>D</RootNamespace>
<AssemblyName>D</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<PackageId>MyCompany.Nuget.D</PackageId>
<PackageVersion>1.0</PackageVersion>
<Author>Me</Author>
<Title>Nuget Experiment Project D</Title>
<Description>Top-level class in the diamond dependency structure</Description>
</PropertyGroup>
I opened the command prompt, navigated to the folder containing my .csproj file, and ran the command nuget spec, as documented here.
However, the resulting .nuspec file looks like this:
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>
<projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
<iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>Tag1 Tag2</tags>
</metadata>
</package>
As you can see, none of the properties I defined in my .csproj file are correctly populated in my .nuspec file.
What am I doing wrong?
EDIT: I initially accepted this answer, but now I don't think it is correct.
I changed the PackageVersion property in my .csproj file to 2.0:
<PackageVersion>2.0</PackageVersion>
If, as the answer claims, the properties in .nuspec are indeed updated during packing by reading from my .csproj file, the new .nupkg file should have the name MyCompany.Nuget.D.2.0.0.nupkg.
However, the new .nupkg file is still named D.1.0.0.nupkg:
EDIT: I followed the instructions included in Leo-MSFT's answer, and changed the AssemblyInfo.cs file to the following:
[assembly: AssemblyTitle("NewD")]
[assembly: AssemblyDescription("Some dummy description")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("MyCompany.Me")]
[assembly: AssemblyProduct("NewD")]
[assembly: AssemblyCopyright("Copyright MyCompany 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("3.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
According to this page, $id$ is retrieved from the AssemblyName field in my .csproj file, and $version$, $author$, $description$ and $copyright$ are retrieved from AssemblyInfo.cs. For that reason, I also updated the AssemblyName field in my .csproj file to MyCompany.NugetTest.D.
I navigated to the folder containing my .sln file, and ran nuget spec "D\D.csproj" as suggested in the answer. The generatednuspec`` file looked like this:
<?xml version="1.0"?>
<package >
<metadata>
<id>D\D.csproj</id>
<version>1.0.0</version>
<authors>Me</authors>
<owners>Me</owners>
<licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>
<projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
<iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package description</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>Tag1 Tag2</tags>
<dependencies>
<dependency id="SampleDependency" version="1.0" />
</dependencies>
</metadata>
</package>
I changed id to SuperUniqueD, and ran nuget pack D.csproj. The package D.3.0.0.nupkg was then created.
Why is the package still named D? Shouldn't it be named MyCompany.NugetTest.D if the value is read from the AssemblyName field in the .csproj file (according to documentation), or NewD if it is read from AssemblyInfo.cs?

