Search code examples
visual-studiomsbuildmsbuildextensionpack

MSBuild.ExtensionPack.tasks inheritance of variables from MSBuild main project file


Case: When I build from MSBuild (with VS Build Tools 2017) I don't get any value for $(ExtensionTasksPath) variable from main msbuild file, when I build with integrated VS MSBuild value is passed from main file to MSBuild.ExtensionPack.tasks, is that expected behavior and why does it happen? I don't use any properties for the sake of testing that particular case.


Solution

  • Is that expected behavior and why does it happen?

    I think it's not we expect.As I test on a VM, the msbuild from VS Build Tools2017 get the same value as what we can get in msbuild from VS IDE.

    For the reason of this behavior I have some suggestions to help trouble shooting:

    1.First of all, make sure both two scenarios builds successfully.

    2.As you mentioned above, you runs them in separate VMs, make sure the two file under test are the same and entire solution folder.(The package folder under solution directory makes sense)

    3.Check in the .xxproj file, check if exists <Import Project="..\packages\MSBuild.Extension.Pack.1.9.1\build\net40\MSBuild.Extension.Pack.targets" ...>

    I've found the $(ExtensionTasksPath) property is defined in MSBuild.Extension.Pack.targets file, and this file is imported into .xxproj file by <Import> tag.

    Have a look at pics below from my sample project which install MSBuild.Extension.Pack by nuget: enter image description here After my project install the extension bu nuget, there is an Import sentence in csproj file, open it we can find:

    enter image description here

    The value of $(ExtensionTasksPath) in defined here. So i guess you may have sth missing with the targets file or the import sentense or have sth corrupt this property.

    In summary:

    1.keep the entire solution folder could be the best suggestion. 2.And if it not works, add a script below to your .xxproj file can work:

    <PropertyGroup>
          <ExtensionTasksPath> Absolute path of your MSBuild.ExtensionPack.dll</ExtensionTasksPath>
    </PropertyGroup>
    

    It will overwrite values from tag and no matter where you put the assembly, just add the absolute path can work. It my answer is helpful, please give me a feedback. And any update please feel free to contact me.