Skip to content

Commit 0e96e39

Browse files
authored
Update info on packing legacy csproj (#3481)
1 parent bbe7bd7 commit 0e96e39

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

docs/consume-packages/migrate-packages-config-to-package-reference.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ You should now be able to see the migration option. Note that this option is not
8787

8888
## Create a package after migration
8989

90-
Once the migration is complete, we recommend that you add a reference to the [nuget.build.tasks.pack](https://www.nuget.org/packages/nuget.build.tasks.pack) nuget package, and then use [msbuild -t:pack](../reference/msbuild-targets.md#pack-target) to create the package. Although in some scenarios you could use `dotnet.exe pack` instead of `msbuild -t:pack`, it is not recommended.
90+
Once the migration is complete, we recommend that you copy your package metadata from a `.nuspec` file to [MSBuild properties](../reference/msbuild-targets.md#pack-target), and then you can use `msbuild -t:pack` to create the package.
91+
If you are using Visual Studio 2022 or earlier, you will also need to install the NuGet.Build.Tasks.Pack package.
92+
From Visual Studio 2026, pack is built into MSBuild.
9193

9294
## Package compatibility issues
9395

docs/create-packages/creating-a-package-msbuild.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ When you create a NuGet package from your code, you package that functionality i
1313

1414
For .NET Core and .NET Standard projects that use the [SDK-style format](../resources/check-project-format.md), and any other SDK-style projects, NuGet uses information in the project file directly to create a package. For a non-SDK-style project that uses `<PackageReference>`, NuGet also uses the project file to create a package.
1515

16-
SDK-style projects have the pack functionality available by default. For non SDK-style PackageReference projects, you need to add the NuGet.Build.Tasks.Pack package to the project dependencies. For detailed information about MSBuild pack targets, see [NuGet pack and restore as MSBuild targets](../reference/msbuild-targets.md).
16+
SDK-style projects have the pack functionality available by default.
17+
For non-SDK-style PackageReference projects, it is also available by default starting from Visual Studio 2026.
18+
In earlier versions of Visual Studio you need to add the NuGet.Build.Tasks.Pack package to the project dependencies and we recommend removing this package reference when upgrading to Visual Studio 2026.
19+
For detailed information about MSBuild pack targets, see [NuGet pack and restore as MSBuild targets](../reference/msbuild-targets.md).
1720

18-
The command that creates a package, `msbuild -t:pack`, is functionally equivalent to `dotnet pack`.
21+
For SDK-style projects, `msbuild -t:pack` is functionally equivalent to `dotnet pack`.
1922

2023
> [!IMPORTANT]
2124
> This topic applies to [SDK-style](../resources/check-project-format.md) projects, typically .NET Core and .NET Standard projects, and to non-SDK-style projects that use PackageReference.
@@ -77,16 +80,33 @@ For details on declaring dependencies and specifying version numbers, see [Packa
7780

7881
[!INCLUDE [choose-package-id](includes/choose-package-id.md)]
7982

80-
## Add the NuGet.Build.Tasks.Pack package
83+
## Configure project for pack
8184

82-
If you are using MSBuild with a non-SDK-style project and PackageReference, add the NuGet.Build.Tasks.Pack package to your project.
85+
SDK-style projects do not require any additional configuration.
8386

84-
1. Open the project file and add the following after the `<PropertyGroup>` element:
87+
Non-SDK-style projects either need at least one package installed (via PackageReference, not packages.config), or the project explicitly needs to instruct NuGet to treat the project as a PackageReference project via the `RestoreProjectStyle` property.
88+
89+
Visual Studio 2022 and earlier does not have pack built-in, so you also need to install the NuGet.Build.Tasks.Pack package.
90+
When upgrading to Visual Studio 2026 or later, we recommend uninstalling the package, so that you benefit from new features and bug fixes.
91+
92+
1. Edit the project file.
93+
94+
If you want to explicitly instruct NuGet to treat the project as PackageReference (the project does not have any packages installed), find or add a `<PropertyGroup>` that does not have any `Condition` statement, and add:
95+
96+
```xml
97+
<PropertyGroup>
98+
<!-- other properties -->
99+
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
100+
<!-- more properties are allowed -->
101+
</PropertyGroup>
102+
```
103+
104+
If you are using Visual Studio 2022 or earlier, add the following after the `<PropertyGroup>` element:
85105

86106
```xml
87107
<ItemGroup>
88108
<!-- ... -->
89-
<PackageReference Include="NuGet.Build.Tasks.Pack" Version="6.7.0" PrivateAssets="all" />
109+
<PackageReference Include="NuGet.Build.Tasks.Pack" Version="6.14.0" PrivateAssets="all" />
90110
<!-- ... -->
91111
</ItemGroup>
92112
```
@@ -98,7 +118,7 @@ If you are using MSBuild with a non-SDK-style project and PackageReference, add
98118

99119
You typically want to start the Developer Command Prompt for Visual Studio from the **Start** menu, as it will be configured with all the necessary paths for MSBuild.
100120

101-
3. Switch to the folder containing the project file and type the following command to install the NuGet.Build.Tasks.Pack package.
121+
3. Switch to the folder containing the project file and type the following command to restore the NuGet.Build.Tasks.Pack package.
102122

103123
```cmd
104124
# Uses the project file in the current folder by default

docs/reference/msbuild-targets.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Similarly, you can write an MSBuild task, write your own target and consume NuGe
3838

3939
For .NET projects that use the `PackageReference` format, using `msbuild -t:pack` draws inputs from the project file to use in creating a NuGet package.
4040

41+
Non-SDK-style projects will need to install the NuGet.Build.Tasks.Pack package when using Visual Studio 2022 or earlier.
42+
We recommend uninstalling this package when upgrading to Visual Studio 2026 to ensure your project can use the latest pack features and bug fixes.
43+
4144
The following table describes the MSBuild properties that can be added to a project file within the first `<PropertyGroup>` node. You can make these edits easily in Visual Studio 2017 and later by right-clicking the project and selecting **Edit {project_name}** on the context menu. For convenience, the table is organized by the equivalent property in a [`.nuspec` file](../reference/nuspec.md).
4245

4346
> [!NOTE]
@@ -307,7 +310,8 @@ When using `MSBuild -t:pack -p:IsTool=true`, all output files, as specified in t
307310

308311
### Packing using a `.nuspec` file
309312

310-
Although it is recommended that you [include all the properties](../reference/msbuild-targets.md#pack-target) that are usually in the `.nuspec` file in the project file instead, you can choose to use a `.nuspec` file to pack your project. For a non-SDK-style project that uses `PackageReference`, you must import `NuGet.Build.Tasks.Pack.targets` so that the pack task can be executed. You still need to restore the project before you can pack a nuspec file. (An SDK-style project includes the pack targets by default.)
313+
Although it is recommended that you [include all the properties](../reference/msbuild-targets.md#pack-target) that are usually in the `.nuspec` file in the project file instead, you can choose to use a `.nuspec` file to pack your project.
314+
You still need to restore the project before you can pack a nuspec file. (An SDK-style project includes the pack targets by default.)
311315

312316
The target framework of the project file is irrelevant and not used when packing a nuspec. The following three MSBuild properties are relevant to packing using a `.nuspec`:
313317

0 commit comments

Comments
 (0)