none
MS Build 15 error

    Question

  • I'm using Visual Studio 2017 15.5.2 (.NET 4.7 installed) and trying to get started with Roslyn with the repo here https://github.com/Apress/code-generation-w-roslyn and when I try to run this program

    using Microsoft.CodeAnalysis.MSBuild;

    var work = MSBuildWorkspace.Create();                
    var solution = work.OpenSolutionAsync(@"..\\..\\..\\RoslynPlayground.sln").Result; //exception

    In the .csproj file the import statement is pointing to a directory that doesn't exist I think because of https://docs.microsoft.com/en-us/visualstudio/msbuild/what-s-new-in-msbuild-15-0 Changed Path

    What's the correct way to set this property by default so it points to the updated path?

    Saturday, December 30, 2017 6:36 PM

Answers

  • Hi wootscootinboogie,

    Welcome to MSDN forum.

    >>>What's the correct way to set this property by default so it points to the updated path?

    When you check the source code from the GitHub, you will find this solution is created by Visual Studio 2015. So when you run this program without Visual Studio, those import statements still point to the Visual Studio 2015 installation directory.

    To resolve this issue, you should initialization your environment before run that program, so that the import statements are pointing to the Visual Studio installation directly(VS2017). You can execute the VsDevCmd.bat file to initialization your environment, this file exists in the directly:

    C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools

    I have created a test sample project with Visual Studio 2015, so the import statements $(MSBuildExtensionsPath) and $(MSBuildToolsVersion) are pointing to C:\Program Files (x86)\MSBuild and 14.0. If I open a cmd and switch to the path C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools and execute VsDevCmd.bat file, the value of $(MSBuildExtensionsPath) and $(MSBuildToolsVersion) will point to  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild and 15.0.

    Besides, there is another way to set this property to the updated path, edit .csproj file and add following code:

      <PropertyGroup>
        <MSBuildExtensionsPath>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0</MSBuildExtensionsPath>
      </PropertyGroup>

    And change the ToolsVersion="14.0" to ToolsVersion="15.0"

    But this method need modify each .csproj file.

    Hope this helps.


    MSDN Community Support Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; 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.


    Monday, January 01, 2018 7:22 AM

All replies

  • I'm using Visual Studio 15.5.2 (.NET 4.7 installed) and trying to get started with Roslyn with the repo here https://github.com/Apress/code-generation-w-roslyn and when I try to run this program

    using Microsoft.CodeAnalysis.MSBuild;

    var work = MSBuildWorkspace.Create();                
    var solution = work.OpenSolutionAsync(@"..\\..\\..\\RoslynPlayground.sln").Result; //exception

    In the .csproj file the import statement is pointing to a directory that doesn't exist I think because of https://docs.microsoft.com/en-us/visualstudio/msbuild/what-s-new-in-msbuild-15-0 Changed Path

    What's the correct way to set this property by default so it points to the updated path?

    Saturday, December 30, 2017 6:26 PM
  • Thank you.
    Saturday, December 30, 2017 6:36 PM
  • Hi wootscootinboogie,

    Welcome to MSDN forum.

    >>>What's the correct way to set this property by default so it points to the updated path?

    When you check the source code from the GitHub, you will find this solution is created by Visual Studio 2015. So when you run this program without Visual Studio, those import statements still point to the Visual Studio 2015 installation directory.

    To resolve this issue, you should initialization your environment before run that program, so that the import statements are pointing to the Visual Studio installation directly(VS2017). You can execute the VsDevCmd.bat file to initialization your environment, this file exists in the directly:

    C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools

    I have created a test sample project with Visual Studio 2015, so the import statements $(MSBuildExtensionsPath) and $(MSBuildToolsVersion) are pointing to C:\Program Files (x86)\MSBuild and 14.0. If I open a cmd and switch to the path C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools and execute VsDevCmd.bat file, the value of $(MSBuildExtensionsPath) and $(MSBuildToolsVersion) will point to  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild and 15.0.

    Besides, there is another way to set this property to the updated path, edit .csproj file and add following code:

      <PropertyGroup>
        <MSBuildExtensionsPath>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0</MSBuildExtensionsPath>
      </PropertyGroup>

    And change the ToolsVersion="14.0" to ToolsVersion="15.0"

    But this method need modify each .csproj file.

    Hope this helps.


    MSDN Community Support Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; 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.


    Monday, January 01, 2018 7:22 AM