Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Update eligible projects to new SDK format. #1761

Merged
merged 26 commits into from
Sep 10, 2018
Merged

Conversation

grokys
Copy link
Contributor

@grokys grokys commented Jun 22, 2018

Now we're using VS2017 we can use the new simplified SDK-style .csproj format. This PR updates the projects that can be updated to this format. It also enables Microsoft.CodeAnalysis.FxCopAnalyzers on them, which is the successor to CodeAnalysis. I've not enabled warnings as errors yet though, because these analyzers find a fair few problems that will need to be fixed first.

WPF projects and VSSDK projects can't use the SDK format yet. In addition GitHub.TeamFoundation.15 uses an alias on a nuget package which can't currently be done, so the GitHub.TeamFoundation.X projects haven't been converted.

@grokys grokys force-pushed the refactor/sdk-csproj branch from 434565b to 624b6c6 Compare June 22, 2018 14:03
@Neme12
Copy link
Contributor

Neme12 commented Jun 22, 2018

VSSDK projects can't use the SDK format yet

I've seen VS extension projects using the new project system in Microsoft repos, for example here:
/~https://github.com/dotnet/roslyn/blob/master/src/VisualStudio/Setup/VisualStudioSetup.csproj
and
/~https://github.com/dotnet/project-system/blob/master/src/ProjectSystemSetup/ProjectSystemSetup.csproj

but haven't found any info or documentation on that. Maybe this is an experimental & undocumented feature?

@jcansdale
Copy link
Collaborator

I appears the nunit3-vs-adapter recently went through a similar process nunit/nunit3-vs-adapter#499.

Maybe @jnm2 will have some tips for us. 😄

@Neme12
Copy link
Contributor

Neme12 commented Jun 23, 2018

@jcansdale I think you can use PackageReference even without the new project file format, it should be orthogonal to that.

@Neme12
Copy link
Contributor

Neme12 commented Jun 23, 2018

In fact I thought this would be at least a 2-step transition with multiple PRs to make this huge change easier to review and take iteratively.

@jnm2
Copy link

jnm2 commented Jun 23, 2018

Sorry to disappoint, but when I looked at the VSIX project, I didn't see any ROI in getting it working with the new SDK. It's possible Oren has something up his sleeve—I know he has WPF working on the new csproj SDK. /~https://github.com/onovotny/MSBuildSdkExtras#msbuildsdkextras

@Neme12
Copy link
Contributor

Neme12 commented Jun 23, 2018

I don't understand what the problem with WPF is? I just tried creating a new WPF project & changing the csproj and everything worked fine.

The only problem is that .xaml files are not included properly by default, so you have to list each one of them in the csproj just like today. At least that's what I thought until I found this:
microsoft/VSProjectSystem#169 (comment)

So using that, now the csproj looks like:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net46</TargetFramework>
    <OutputType>WinExe</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System.Xaml" />
    <Reference Include="WindowsBase" />
    <Reference Include="PresentationCore" />
    <Reference Include="PresentationFramework" />
  </ItemGroup>
  <ItemGroup>
    <None Remove="**\*.xaml" />
    <ApplicationDefinition Include="App.xaml">
      <Generator>MSBuild:Compile</Generator>
      <SubType>Designer</SubType>
    </ApplicationDefinition>
    <Page Include="**\*.xaml" Exclude="App.xaml">
      <Generator>MSBuild:Compile</Generator>
      <SubType>Designer</SubType>
    </Page>
    <Compile Update="**\*.xaml.cs">
      <DependentUpon>%(Filename)</DependentUpon>
      <SubType>Code</SubType>
    </Compile>
  </ItemGroup>
</Project>

everything works perfectly and it is stable when adding/removing xaml files inside VS (it doesn't modify the project file to add duplicate items).

for a library, the includes would be simplified to:

  <ItemGroup>
    <None Remove="**\*.xaml" />
    <Page Include="**\*.xaml">
      <Generator>MSBuild:Compile</Generator>
      <SubType>Designer</SubType>
    </Page>
    <Compile Update="**\*.xaml.cs">
      <DependentUpon>%(Filename)</DependentUpon>
      <SubType>Code</SubType>
    </Compile>
  </ItemGroup>

@grokys grokys force-pushed the refactor/sdk-csproj branch from 624b6c6 to f58e177 Compare June 25, 2018 09:07
grokys added 2 commits June 25, 2018 11:10
WPF projects and VSSDK projects can't use the SDK format yet. In addition `GitHub.TeamFoundation.15` uses an alias on a nuget package which can't currently be done, so the `GitHub.TeamFoundation.X` projects haven't been converted.
@grokys grokys force-pushed the refactor/sdk-csproj branch from 5b691b1 to 3eeb718 Compare June 25, 2018 09:10
grokys added 4 commits June 25, 2018 11:51
Had to also remove the `<RootNamespace>` as it was causing the resources to get generated in the wrong place.
Also
- Removed more unnecessary dependencies
- Moved a couple of tests to the right project
- Removed `GitHub.Primitives.UnitTests` as it was testing stuff in `GitHub.Exports`, so moved to `GitHub.Exports.UnitTests`
@meaghanlewis meaghanlewis added this to the 2.5.4 milestone Jun 25, 2018
<PropertyGroup>
<Product>GitHub Extension for Visual Studio</Product>
<Version>2.5.4.0</Version>
<Copyright>Copyright © GitHub, Inc. 2014-2018</Copyright>
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could maybe do something like this to future-proof... 😉

<CopyrightYear>$([System.DateTime]::Now.ToString("yyyy"))</CopyrightYear>
<Copyright>Copyright © GitHub, Inc. 2014-$(CopyrightYear)</Copyright>

Copy link
Collaborator

@jcansdale jcansdale left a comment

Choose a reason for hiding this comment

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

I'm confused where this project gets its VS SDK references from.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm confused where this project gets its VS SDK references from.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It gets them from GitHub.Exports.

grokys added 2 commits June 26, 2018 16:22
Having them be PCL meant that we had to have both a PCL and .netfx version of Splat, which was causing problems with test runners because they would load the wrong version of the library at random.
@grokys
Copy link
Contributor Author

grokys commented Jun 26, 2018

@Neme12 yep, i've managed to get WPF projects working now. Thanks for the pointer - I'd tried something similar before but couldn't get it to work. Not sure what I was missing.

<DependentUpon>%(Filename)</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="**\*.xaml">
Copy link
Contributor

@Neme12 Neme12 Jun 26, 2018

Choose a reason for hiding this comment

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

The reason why I included <None Remove="**\*.xaml" /> before this in my example is that without that, when adding a new xaml control inside VS, it adds a new line here with <None Remove="AddedFile.xaml" />

But I have no idea how this behaves and what VS would do when this is in am imported project. Did you check that it works properly and doesn't modify the csproj?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm yeah you're right, it does modify the .csproj...

Copy link
Contributor Author

@grokys grokys Jun 26, 2018

Choose a reason for hiding this comment

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

Looks like this is the associated issue: dotnet/project-system#3639

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think for the moment I'm going to revert the change for converting our WPF projects to the new csproj and try again when 15.8 is available.

Copy link
Contributor

@Neme12 Neme12 Jun 27, 2018

Choose a reason for hiding this comment

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

I didn't think this was a bug. They are included as None by default so VS tries to do its best to undo that and make sure they're only included as Page.

grokys added 3 commits June 27, 2018 09:44
 Conflicts:
	test/Helpers/SplatModeDetectorSetUp.cs
They weren't getting included in the vsix.
@meaghanlewis meaghanlewis removed this from the 2.5.4 milestone Jul 13, 2018
@jnm2
Copy link

jnm2 commented Jul 16, 2018

@jnm2
Copy link

jnm2 commented Jul 19, 2018

It's been amazing. In all seriousness, I wonder what the telemetry would report if it was a native and documented feature.

@grokys
Copy link
Contributor Author

grokys commented Aug 24, 2018

@sharwell just got back to this and tried using MSBuild.Sdk.Extras but I'm still getting the:

  <ItemGroup>
    <Compile Remove="Controls\UserControl1.xaml.cs" />
  </ItemGroup>

added whenever I add a XAML/cs file combination, and they don't appear nested.

@clairernovotny
Copy link

Have you added <ExtrasEnableWpfProjectSetup>true</ExtrasEnableWpfProjectSetup> to your project? That turns on the WPF defaults.

@grokys
Copy link
Contributor Author

grokys commented Aug 25, 2018

@onovotny yeah, I have. Just pushed the commit with the change in. If you want to try it, try going to GitHub.UI and adding a WPF user control and saving the solution.

@grokys
Copy link
Contributor Author

grokys commented Sep 5, 2018

@onovotny this seems to be fixed with MSBuild.Sdk.Extras 1.6.52 - thanks!

@grokys grokys changed the title WIP: Update eligible projects to new SDK format. Update eligible projects to new SDK format. Sep 5, 2018
@meaghanlewis meaghanlewis added this to the 2.5.6 milestone Sep 5, 2018
Copy link
Contributor

@shana shana left a comment

Choose a reason for hiding this comment

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

Looks good in general, I'm just wondering where the settings for code analysis are. The csproj point to a specific ruleset, but this new format doesn't seem to have that setting or any configuration to enable/disable and set warnings as errors. Given how many warnings are on CI, I'm guessing it's using the default ruleset for these?

@@ -17,7 +17,7 @@

public class VSGitExtTests
{
public class TheConstructor : TestBaseClass
public class TheConstructor
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this inheritance changing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ummm... I can't remember. I'll put this back.

@grokys
Copy link
Contributor Author

grokys commented Sep 6, 2018

Looks good in general, I'm just wondering where the settings for code analysis are.

Yes it's using the default ruleset for now, and not enabling warnings as errors. The new analyser has a lot more checks that are very useful and that I don't want to disable (such as always using ConfigureAwait() on Tasks) but I didn't want to litter this PR with changes to fix these warnings.

My reasoning was that we should fix these warnings and enable warnings as errors in a separate PR.

@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Product>GitHub Extension for Visual Studio</Product>
<Version>2.5.5.0</Version>
<Version>2.5.6.0</Version>

Choose a reason for hiding this comment

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

Do you need to manually version? There are better ways to do this :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh really? Please do elucidate! What would be a better way to do this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've always hated version stamping. I'd be interested in finding the least-hacky way! 😉

Choose a reason for hiding this comment

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

I have a project that matches this one very closely -- xUnit for Devices. It has a VSIX for its templates and auto-versions.

/~https://github.com/xunit/devices.xunit

Here are some key things:

  1. Uses Nerdbank.GitVersioning to get a version for each commit. That handles the csproj's.
  2. Build scripts update other xml assets to match: /~https://github.com/xunit/devices.xunit/blob/master/.vsts-shared.yml#L31-L36

Copy link
Collaborator

@jcansdale jcansdale left a comment

Choose a reason for hiding this comment

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

This seems to work well and it's impressive how much the size of .csproj files have been reduced. I think if we delay merging this now, we'll have nasty merge issues further down the road. I'd say LGTM since we're at the beginning a of a dev cycle.

@grokys grokys merged commit 4eef5b3 into master Sep 10, 2018
@grokys grokys deleted the refactor/sdk-csproj branch September 10, 2018 12:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants