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

Project platform settings other than "Any CPU" are ignored #6535

Open
bashtavenko opened this Issue Nov 3, 2015 · 6 comments

Comments

Projects
None yet
6 participants
@bashtavenko
Copy link

bashtavenko commented Nov 3, 2015

If project in the solution has platform settings other than "Any CPU" (x86, x64), Roslyn picks incorrect configuration. For example, if one of the projects has OutputPath of "bin\x86\Debug"

 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\x86\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x86</PlatformTarget>

This code returns "bin\Debug" in project,OutputFilePath. Other project properties are also incorrect and correspond to "Any CPU" as opposed to "x86".

using (var workspace = MSBuildWorkspace.Create())
{
    var solution = workspace.OpenSolutionAsync(solutionPath).Result;
    foreach (var project in solution.Projects)
    {
        var projectModulePath = project.OutputFilePath;
        //...
    }
}
@Pilchie

This comment has been minimized.

Copy link
Member

Pilchie commented Nov 3, 2015

You should be able to pass Configuration and Platform as part of the properties parameter of MSBuildWorkspace.Create(IDictionary<string, string> properties)

@bashtavenko

This comment has been minimized.

Copy link

bashtavenko commented Nov 4, 2015

When there are multiple configurations in the solution, Visual Studio sets platform drop down to "Mixed Platforms" automatically

GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Debug|Mixed Platforms = Debug|Mixed Platforms
        Debug|x86 = Debug|x86
    EndGlobalSection

.. and thus after build the assemblies go to ".bin\x86\Debug.." folder. When the same solution is opened in Roslyn, it appears that it picks up "Debug|Any CPU" configuration and thinks that assemblies should be in "bin\Debug", but they aren't there.

I understand that I can pass Configuration and Platform, but given a solution, how do I know what these parameters should be?

@Pilchie Pilchie added Enhancement and removed Question labels Nov 6, 2015

@Pilchie

This comment has been minimized.

Copy link
Member

Pilchie commented Nov 6, 2015

Oh, good point. I didn't really think about the default configurations stored in the .sln file. We should probably use those when loading an sln. I'm not sure if MSBuild added sufficient solution parsing APIs for that, but if so, we'd want to look at updating the code around here

@Pilchie Pilchie reopened this Nov 6, 2015

@Pilchie Pilchie added Area-IDE and removed Resolution-Answered labels Nov 6, 2015

@Pilchie Pilchie added this to the 1.2 milestone Nov 6, 2015

bashtavenko added a commit to bashtavenko/CodeVision that referenced this issue Nov 10, 2015

@jaredpar jaredpar removed this from the 1.2 milestone Nov 23, 2015

@davkean davkean added this to the 1.2 milestone Dec 4, 2015

@Pilchie Pilchie modified the milestones: 1.2, 1.3 Jan 23, 2016

@Pilchie Pilchie modified the milestones: 2.0 (RC), 1.3 May 27, 2016

@Pilchie Pilchie modified the milestones: 2.0 (Preview 5), 2.0 (RC) Sep 26, 2016

@Pilchie Pilchie modified the milestones: 2.0 (RTM), 2.0 (RC) Nov 2, 2016

@Pilchie Pilchie modified the milestones: 3.0, 2.0 (RTM) Jan 19, 2017

@Pilchie

This comment has been minimized.

Copy link
Member

Pilchie commented Jan 19, 2017

Is #6709 the same issue?

@mattwar

This comment has been minimized.

Copy link
Contributor

mattwar commented Jan 19, 2017

Yes. Msbuild workspace has no logic for picking a configuration. Currently it requires the caller to set the configuration as a property. If not specified it just defaults to whatever the default of the project file.

@Ziriax

This comment has been minimized.

Copy link

Ziriax commented Aug 26, 2017

Today we upgraded to Visual Studio 2017 15.3.2. One of our code-generation projects uses Roslyn's MSBuildWorkspace (version 2.3.1), and we're explicitly passing x86 as the platform and Diagnostics as our (custom) configuration. This worked fine until today, but after the upgrade each Project is loaded completely empty (no document, empty OutputPath, etc). On another workstation where we did not do the upgrade, everything still works fine. I tried doing a system restore but that completely broke Visual Studio. Any idea what could be going wrong? We have an MSDN Enterprise subscription, I'm waiting for support from that source too.

UPDATE: Go figure, the Project instance is only empty when debugging or running from Visual Studio or CMD.exe. When I run the code generation tool using the Visual Studio 2017 Developer Command Prompt it works! So it seems to be picking up wrong assemblies when the executing environment is VS2017 or CMD.exe.

UPDATE2: It seems the following two environment variables need to be changed for our tool to run under CMD.exe:

set VisualStudioVersion=15.0
set VSINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment