MSBuild clean directory string

守給你的承諾、 提交于 2019-12-24 00:53:45

问题


I have a property in MSBuild to represent the directory above the MSBuildProjectDirectory:

<PropertyGroup>
    <BuildDir>$(MSBuildProjectDirectory)\..</PRSBuildDir>
</PropertyGroup>

I need to then use this property, but I need the directory string cleaned so that it doesn't include the ... In other words I need the .. evaluated, so that if the current project file is in C:\Test\Tom\MyDir, then I need a property containing the string C:\Test\Tom.

The reason I'm asking is because I'm trying to run a command like this:

msiexec /passive /i "D:\Build\2.3.84.40394\Deployment\..\Vendor\LogParser.msi"

But it's complaining about the path to the msi: This installation package could not be opened. Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer package.


回答1:


There's a ConvertToAbsolutePath task, that any use?




回答2:


The best method I've got right now is below, but I was wondering if there might be a better way..

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <PropertyGroup>
        <BuildDir>$(MSBuildProjectDirectory)\..</BuildDir>
    </PropertyGroup>

    <Target Name="Test">
        <ItemGroup>
            <CleanBuildDir Include="$(BuildDir)" />
        </ItemGroup>

        <PropertyGroup>
            <BuildDir>%(CleanBuildDir.FullPath)</BuildDir>
        </PropertyGroup>

        <Message Text="$(BuildDir)" />
    </Target>
</Project>



回答3:


If you want to have wildcard evaluated, you should use Item instead of Property.

<ItemGroup>
  <BuildDir Include="$(MSBuildProjectDirectory)\.."/>
</ItemGroup>

<Target Name="ExecMSIExec">
  <Exec Command="msiexec /passive /i %(BuildDir.FullPath)\Vendor\LogParser.msi"/>
</Target>



回答4:


(deleted my answer as I didn't see that Tom had answered in exactly the same way!)

By the way, why don't you set the "WorkingDirectory" attribute of the Exec task where you actually call msiexec to be the location of your MSI - that way you won't run into an path length issues



来源:https://stackoverflow.com/questions/3425089/msbuild-clean-directory-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!