Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate all NuGet.Client projects to SDK style #5167

Merged
merged 8 commits into from May 16, 2023
Merged

Conversation

zivkan
Copy link
Member

@zivkan zivkan commented May 12, 2023

Bug

Fixes: https://github.com/NuGet/Client.Engineering/issues/273

Regression? No

Description

Migrate all non-SDK style projects in the solution to SDK style. VS still providers designers for WPF and WinForms, so I don't believe there's any downside to this. I tested that code changes and F5 debug into VS experimental instance still works. The solution can now be restored and evaluated with the dotnet CLI, but the VSSDK.BuildTools tasks only run on msbuild, so we can't build with the dotnet CLI.

The changes are mostly "simple" conversions, but there's a few non-trivial things that needed to be done:

  • SDK style WinForms resources always use project default namespace, forcing all the PM UI options pages to change namespace
  • AfterBuild targets needed to be changed due to targets files import order changing.
  • Projects using VSSDK.BuildTools have a minor issue. See comment below.
  • NuGet.VisualStudio.Client.csproj needs the <Name> metadata on all the <ProjectReference items that are defined in the vsixmanifest file, because the VSSDK BuildTools needs it. We also need all the ngen metadata. We can convert the syntax to XML attributes rather than child elements, but I don't find either syntax better or worse than the other.

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added
    • OR
    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A

@zivkan zivkan requested a review from a team as a code owner May 12, 2023 07:51
@@ -0,0 +1,4 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />
<Import Project="$(PkgMicrosoft_VSSDK_BuildTools)\tools\VSSDK\Microsoft.VsSDK.targets" Condition="'$(PkgMicrosoft_VSSDK_BuildTools)' != ''" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Microsoft.VsSDK.targets file needs to be imported AFTER all the .NET/msbuild common targets are imported. Since the project file uses <Project Sdk="Microsoft.NET.Sdk>, the project file no longer explicitly imports the targets in the file, allowing us to add extra MSBuild script after the targets import.

However, MSBuild allows you to explicitly import the SDK's props and targets files in the project file. If we change to this syntax, we shouldn't need to add these Directory.Build.targets files. What do people think?

For what it's worth, I also tried moving this import to build/common.targets, but for reasons I don't understand, it caused two resources files in the NuGet.Tools project to have the same output path, which failed the build.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this more elegant, I'm hoping they fix it in the future too so its even easier to have and SDK-style project for VSIX.

Here's the alternative in action for others to compare: https://github.com/microsoft/slngen/blob/main/src/Microsoft.VisualStudio.SlnGen.Extension/Microsoft.VisualStudio.SlnGen.Extension.csproj#L49-L50

@@ -14,7 +14,7 @@
</PropertyGroup>

<PropertyGroup>
<ReferenceOutputPath>$(ArtifactsDirectory)NuGet.VisualStudio.Client\bin\$(Configuration)\</ReferenceOutputPath>
<ReferenceOutputPath>$(ArtifactsDirectory)NuGet.VisualStudio.Client\bin\$(Configuration)\net472\</ReferenceOutputPath>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative would be to set <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> in NuGet.VisualStudio.Client.csproj since it won't ever multi-target.

<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources.resx">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SDK-style projects usually need an <EmeddedResource Update="" /> to make things look right in VS.

https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Versioning/NuGet.Versioning.csproj#L20-L33

@@ -0,0 +1,4 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />
<Import Project="$(PkgMicrosoft_VSSDK_BuildTools)\tools\VSSDK\Microsoft.VsSDK.targets" Condition="'$(PkgMicrosoft_VSSDK_BuildTools)' != ''" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this more elegant, I'm hoping they fix it in the future too so its even easier to have and SDK-style project for VSIX.

Here's the alternative in action for others to compare: https://github.com/microsoft/slngen/blob/main/src/Microsoft.VisualStudio.SlnGen.Extension/Microsoft.VisualStudio.SlnGen.Extension.csproj#L49-L50

Copy link
Contributor

@jeffkl jeffkl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@zivkan zivkan merged commit b2f1521 into dev May 16, 2023
13 of 15 checks passed
@zivkan zivkan deleted the dev-zivkan-sdkify-projects branch May 16, 2023 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants