microsoft / VSProjectSystem

Documentation for extending Visual Studio with new types of projects.
Other
311 stars 87 forks source link

Templates - SDK style projects. #257

Open dazinator opened 6 years ago

dazinator commented 6 years ago

For some fun, I updated my csproj file for my ProjectType project (the one that produces a VSIX) to use the new SDK format / style.

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">  

In about half an hour I have the project building. Many references became <PackageReference>s.

The main reason I wanted this is because I wanted to use globbing on includes to help resolve the problem in #167

Sadly though, even though the project builds - when I check the output directory there is no vsix. Also it seems the xaml rules that allowed for properties like "IncludeInVsix" are no longer present as those options have disappeared from the property sheet.

In brief.. Do you have any plans to provide templates based on the new format any time soon? So we can use new project system features?

jp2masa commented 6 years ago

You need many MSBuild "hacks" to get a vsix using the new project system, and there are many UI features missing for VSIX development. You need to import the VSSDK targets after importing Sdk.targets. This is the project I use, which has some "hacks" to make WPF work in the new project system too: https://github.com/CosmosOS/XSharp/blob/master/source/XSharp.ProjectSystem/XSharp.ProjectSystem.csproj

dazinator commented 6 years ago

@jp2masa - thank you very much, this was very helpful. I now have the project building and producing a vsix :-)

One problem I have noticed, is that the VSIX is set to install the BuildSystem (targets, rules etc) to [INSTALLDIR]\MSBuild

However the project templates have this:

 <CustomProjectExtensionsPath>$(LocalAppData)\CustomProjectSystems\XSharp\</CustomProjectExtensionsPath>

https://github.com/CosmosOS/XSharp/blob/master/source/XSharp.ProjectSystem/ProjectTemplates/XSharp%20Library%20Project/XSharpProject.xsproj#L9

The build system is copied to LocalAppData on build, which is why this will work locally, but when installed via the VSIX it won't work.

Are you aware of any msbuild property that can be used within the project file that will point to [INSTALLDIR]\MSBuild directory of the VS instance?

e.g I am looking for a property to use like this:

<CustomProjectExtensionsPath>$(VS INSTALL DIR)\MsBuild\CustomProjectSystems\XSharp\</CustomProjectExtensionsPath>
jp2masa commented 6 years ago

The build system is not finished, as for now it's a bit hard to ship a custom SDK. Currently the project system is usable only if targets are manually imported: https://github.com/CosmosOS/XSharp/blob/master/source/XSharp.Playground/XSharp.Playground.xsproj. Rules and design time targets are installed to $(MSBuildExtensionsPath), and they are consumed by the SDK: https://github.com/CosmosOS/XSharp/blob/master/source/XSharp.Sdk/build/XSharp.Build.targets#L13.

dazinator commented 6 years ago

Ah Ok thanks. MSBuildExtensionsPath was the msbuild property I was looking for! Before that, I was using: $(DevEnvDir)..\..\MsBuild\ to refer to that same location :-)

dazinator commented 6 years ago

Interesting. So MSBuildExtensionsPath works in that it points to C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild when running under VS, and this is where the VSIX installs things too when using an InstallRoot of MSBuild - which is great.

However, if you then drop the command line and run a dotnet build.. MSBuildExtensionsPath doesn't point to that location any longer. So it ends up looking in: C:\Program Files\dotnet\sdk\2.0.0 (i.e the root directory of whichever version of the dotnet sdk you have installed) - and obviously the targets aren't deployed to this location by the VSIX. so it wont work. App Local Data doesn't have this problem, but obviouilsy yuou cannot deploy to App Local Data via a VSIX so this isn't an option for me).

My build system does support dotnet core (all my tasks are compatible with both dotnet core and desktop msbuild), but I was hoping to streamline the installation by installing purely via a VSIX (i.e no msi).

The only way I can get this working with dotnet sdk is to make the user specify this property i.e:

dotnet pack /p:PackageVersion=2.1.0 /p:MSBuildExtensionsPath="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild"

This then works, but it is not ideal.

jp2masa commented 6 years ago

If you are extending the dotnet project system, then the best option would be to ship the build system as a nuget package. If not, then I think it's not possible. In the X# project system, only the design time targets and rules are installed in $(MSBuildExtensionsPath), because they are consumed by VS, but the rest of the build system will ship as an MSBuild SDK, which currently is limited, but will support SDKs coming from a NuGet package. PackageReference is implemented for the dotnet and legacy project systems only, and that's the best option to extend the build system at the moment.

dazinator commented 6 years ago

@jp2masa - I have been using your example csproj file for a while: https://github.com/CosmosOS/XSharp/blob/master/source/XSharp.ProjectSystem/XSharp.ProjectSystem.csproj

However today I added an xaml file to my project, and it gives me some build errors. Just wondering if you might have come accross this:

Severity Code Description Project File Line Suppression State Error MC1002 Library project file cannot specify ApplicationDefinition element. DnnVsProjectSystem.ProjectType C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets 268

Severity Code Description Project File Line Suppression State Error BG1003 The project file contains a property value that is not valid. DnnVsProjectSystem.ProjectType C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets 268

It's odd because the Build Action shows in the property pages window for the xaml file as None However in the csproj file it's clearly listed as Page:


<ItemGroup>
    <Page Include="Licence\LicenceScreen.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:Compile</Generator>
    </Page>
    <Compile Update="Licence\LicenceScreen.xaml.cs">
      <DependentUpon>LicenceScreen.xaml</DependentUpon>
    </Compile>
  </ItemGroup>

The designer seems to work fine.

If I change the Build Action in the properties window to Page - VS adds the following entry to the project file:

<None Remove="Licence\LicenceScreen.xaml" />

and it then becomes greyed out in solution explorer like it's been excluded from my project. Very odd!

jp2masa commented 6 years ago

What VS version are you using? Also, are you specifying any ApplicationDefinition? I recently changed the project file a bit and now it imports some workarounds from Directory.Build.props and Directory.Build.targets, this version should work without any special imports: https://github.com/CosmosOS/XSharp/blob/a8c23c716b5995b40771535b6c9620a941aba0e9/source/XSharp.ProjectSystem/XSharp.ProjectSystem.csproj.

dazinator commented 6 years ago

Ok thanks, I'll triple check over everything

dazinator commented 6 years ago

@jp2masa - An had snuck it's way into my csproj!. Thanks to good old copying and pasting of files between projects.. Thanks for pointing me to the latest version.

kasperk81 commented 3 years ago

@madskristensen or @rainersigwald would probably know who has the authority to create and publish a Microsoft.VisualStudio.SDK.Extensions, named similar to those listed here: https://docs.microsoft.com/en-us/dotnet/core/project-sdk/overview#available-sdks.

That will shave off a lot of xml lines from the world. Everyone would appreciate an SDK style VSIX csproj.

madskristensen commented 3 years ago

@madskristensen or @rainersigwald would probably know who has the authority to create and publish a Microsoft.VisualStudio.SDK.Extensions, named similar to those listed here: https://docs.microsoft.com/en-us/dotnet/core/project-sdk/overview#available-sdks.

Let's ask @tinaschrepfer

CZEMacLeod commented 3 years ago

@madskristensen I guess a lot of this will be internal MS / VisualStudio stuff - updating the custom editors to trigger on CPS project items and what have you, but if you want any help with testing or hooking this up - I did an SDK for the ASP.NET4 / MVC5 / OWIN / WebAPI2 world (to replace web application project) - it is available as MSBuild.SDK.SystemWeb.

kasperk81 commented 3 years ago

Some related resources are: