如何获取 $(MSBuildProjectDirectory) 的最后一部分

发布于 2024-08-29 06:23:09 字数 150 浏览 4 评论 0原文

我不知道如何获取 $(MSBuildProjectDirectory) 的最后一部分。

例如,如果值为“c:\development\projects\project_branch”,那么我只需要最后一部分“project_branch”。

我该怎么做?

I can't figure out how to get the last part of $(MSBuildProjectDirectory).

For example, if the value was "c:\development\projects\project_branch" then I want just the last part "project_branch".

How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

御弟哥哥 2024-09-05 06:23:09

在 4.0+ 中,您可以使用属性函数在一行中完成此操作。

在这种情况下例如
$([System.IO.Path]::GetDirectoryName($(MSBuildProjectDirectory)))

或者您可以使用字符串函数。

In 4.0+ you can use Property Functions to do this in one line.

In this case for example
$([System.IO.Path]::GetDirectoryName($(MSBuildProjectDirectory)))

or you could use a String function.

↙温凉少女 2024-09-05 06:23:09
<Project DefaultTargets="BuildAll" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <Target Name="GetMSBuildProjectLocalDirectory">
        <CreateItem Include="$(MSBuildProjectDirectory)">
            <Output ItemName="MSBuildProjectDirectoryMeta" TaskParameter="Include"/>
        </CreateItem>
        <CreateProperty Value="%(MSBuildProjectDirectoryMeta.Filename)">
            <Output PropertyName="LocalDirectory" TaskParameter="Value"/>
        </CreateProperty>
    </Target>

    <Target Name="BuildAll" DependsOnTargets="GetMSBuildProjectLocalDirectory">
        <Message Text="$(LocalDirectory)" />
    </Target>

</Project>
<Project DefaultTargets="BuildAll" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <Target Name="GetMSBuildProjectLocalDirectory">
        <CreateItem Include="$(MSBuildProjectDirectory)">
            <Output ItemName="MSBuildProjectDirectoryMeta" TaskParameter="Include"/>
        </CreateItem>
        <CreateProperty Value="%(MSBuildProjectDirectoryMeta.Filename)">
            <Output PropertyName="LocalDirectory" TaskParameter="Value"/>
        </CreateProperty>
    </Target>

    <Target Name="BuildAll" DependsOnTargets="GetMSBuildProjectLocalDirectory">
        <Message Text="$(LocalDirectory)" />
    </Target>

</Project>
擦肩而过的背影 2024-09-05 06:23:09

如果您遵循最佳实践,那么您的项目目录将与项目文件同名。因此,您应该能够使用:

$(MSBuildProjectName)

If you're following best practice, then your project directory will have the same name as your project file. Therefore, you should be able to use:

$(MSBuildProjectName)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文