Vs2012 and VS 2013 behave different when trying to manipulate the MSBuild file

Topics: General
Nov 26, 2013 at 7:18 AM
Hi,

I have a Nuget package that is running fine for VS 2012 but does not work correctly in VS 2013.
The solution to import the package to consists of a WPF project and C++ project.
When the package is importeed into a project it modifies the project and adds some property groups and item groups.

To get things running the package contains a Install.ps1. In that script I have the following code:
# Need to load MSBuild assembly if it's not loaded yet.
Add-Type -AssemblyName 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
# Grab the loaded MSBuild project for the project
$msbuildProject = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($project.FullName) | Select-Object -First 1
    
In VS2013 it happens that $msbuildProject is not set up correctly when importing the package in a C++ project. In order to verify what is wrong I checked the content of the GlobalProjectCollection using the following code:
$globalCollection = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection 
Write-Host("Number of loaded projects: {0}" -f $globalCollection.LoadedProjects.Count)
$globalCollection.LoadedProjects | Foreach-Object {Write-Host("Project: {0}"  -f $_.FullPath)}
The strange thing is that in VS 2012 the collection contains all the projects from the solution, in VS2013 I only see the WPF project.

I'm now struggeling to get project modifed during package installation. I already tried manually loading the C++ project but with no success.

Is there any known issue or even better a known workaround for addressing this?

TIA,
Lars
Apr 16, 2014 at 2:24 PM
Any luck with this?

As you say the GlobalProjectCollection.LoadedProjects returns the projects for managed projects but for native C++ projects it's empty. Try the C# and C++ Universal Apps template and you'll see what I mean.