none
Defininig ProjectTypeGuids in p

    Question

  • Is it possible to define the ProjectTypeGuids in an imported Project?

    What I trying to archive is to automatically add a project flavor when a NuGet package is installed, so I define the ProjectTypeGuids in the NuGet package props file.

    I did some testing but Visual Studio seems to ignore ProjectTypeGuids not defined in the main project file, even if they are setting the same MSBuild property.

    Wednesday, January 3, 2018 8:55 PM

All replies

  • Hi pepone.onrez,

    >>Is it possible to define the ProjectTypeGuids in an imported Project?

    Yes, you could. open the nugget nupkg file via tool named Nuget Package Explorer. click content -> Add -> Build Folder.

    Then right click build -> Add .props file, and modify it like below, which will imported to project when you install the package.

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <PropertyGroup>
            <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
        </PropertyGroup>
    </Project>

    >>I did some testing but Visual Studio seems to ignore ProjectTypeGuids not defined in the main project file, even if they are setting the same MSBuild property.

    Because it is only a property in proj file, msbuild may not use it in build target, you could write a custom target to operate it.

    Best regards,

    Zhanglong Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 4, 2018 2:57 AM
    Moderator
  • Hi Zhanglong Wu,

    I already add a props file in the build folder and it is imported when I install the NuGet package on a project.

    But the property is not affecting the project flavor, like when you define the property in the project file.

    What I was trying to archive is to automatically add the project flavor when the NuGet package is installed, rather than have the user edit the project file and add the ProjectTypeGuids

    Thursday, January 4, 2018 9:45 AM
  • My second approach was to use the NuGet Init script and IVsBuildPropertyStorage

    $solution = [Microsoft.VisualStudio.Shell.Package]::GetGlobalService([Microsoft.VisualStudio.Shell.Interop.SVsSolution])
    $solution =  [NuGetConsole.Host.PowerShell.Implementation.PSTypeWrapper]::GetInterface($solution, [Microsoft.VisualStudio.Shell.Interop.IVsSolution])
    $err, $hierarchy = $solution.GetProjectOfUniqueName($project.UniqueName)
    $hierarchy = [NuGetConsole.Host.PowerShell.Implementation.PSTypeWrapper]::GetInterface($hierarchy, [Microsoft.VisualStudio.Shell.Interop.IVsBuildPropertyStorage])
    $hierarchy.SetPropertyValue("ProjectTypeGuids", "", 1, "{3C53C28F-DC44-46B0-8B85-0C96B85B2042};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}")

    The problem with that is the semicolon gets escaped as %3b in the project file and will fail to load

        <ProjectTypeGuids>{3C53C28F-DC44-46B0-8B85-0C96B85B2042}%3b{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

    Can you think of other approach to automatically add the ProjectTypeGuids?

    Thursday, January 4, 2018 12:31 PM