使用 msbuild 扩展包 detokenise 的属性范围

发布于 2024-11-19 12:12:39 字数 1623 浏览 1 评论 0原文

我尝试使用 msbuild 扩展包来修复我们的应用程序在部署时的配置, 我希望能够传递一个属性(ENV),它将加载我的环境特定配置文件以与 detokeniser 一起使用,并修复我的应用程序配置。 像这样:

    <UsingTask TaskName="MSBuild.ExtensionPack.FileSystem.Detokenise"
           AssemblyFile=".\Tools\MSBuild Extension Pack 4.0.3.0\MSBuild.ExtensionPack.dll"/>
<Import Project=".\Environments\$(Env).properties"/>
<Target Name="Build" >
    <ItemGroup>
        <SourceTemplates Include=".\Templates\**\*.*"/>
    </ItemGroup>

    <RemoveDir Directories=".\Temp"/>
    <MakeDir Directories=".\Temp"/>

    <Message Text="@(SourceTemplates)"/>

    <Copy SourceFiles="@(SourceTemplates)"
          DestinationFolder=".\Temp\%(RecursiveDir)" />

    <ItemGroup>
        <TargetTemplates Include=".\Temp\**\*.*"/>
    </ItemGroup>

    <MSBuild.ExtensionPack.FileSystem.Detokenise
         TaskAction="Detokenise"
         TargetFiles="@(TargetTemplates)"/>
</Target>

所以我使用

msbuild Detokenise.msbuild /p:Env=Prod

Msbuild 知道我的文件并且我可以访问它的属性,但是当 detokeniser 运行时我收到错误:

Detokenise Task Execution Completed [15:07:50]
C:\Source\1.2\Build\Detokenise.msbuild(27,3):
error : InvalidProjectFileException: The imported project "C:\Source\1.2\Build\Environments\.properties" was not found.
Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
C:\Source\1.2\Build\Detokenise.msbuild\r
C:\Source\1.2\Build\Detokenise.msbuild(27,3): error :

如果我对其进行硬编码,则一切正常 - 任何想法如何解决这个问题。我想在执行之前在 msbuild 上进行一些文本替换...

Im trying to use the msbuild extensions pack to fix up the configuration of our app on deploy,
i want to be able to pass a property (ENV) which will load my environment specific config file to use with the detokeniser, and fix up my application configs.
Like this:

    <UsingTask TaskName="MSBuild.ExtensionPack.FileSystem.Detokenise"
           AssemblyFile=".\Tools\MSBuild Extension Pack 4.0.3.0\MSBuild.ExtensionPack.dll"/>
<Import Project=".\Environments\$(Env).properties"/>
<Target Name="Build" >
    <ItemGroup>
        <SourceTemplates Include=".\Templates\**\*.*"/>
    </ItemGroup>

    <RemoveDir Directories=".\Temp"/>
    <MakeDir Directories=".\Temp"/>

    <Message Text="@(SourceTemplates)"/>

    <Copy SourceFiles="@(SourceTemplates)"
          DestinationFolder=".\Temp\%(RecursiveDir)" />

    <ItemGroup>
        <TargetTemplates Include=".\Temp\**\*.*"/>
    </ItemGroup>

    <MSBuild.ExtensionPack.FileSystem.Detokenise
         TaskAction="Detokenise"
         TargetFiles="@(TargetTemplates)"/>
</Target>

So i call this using

msbuild Detokenise.msbuild /p:Env=Prod

Msbuild knows about my file and i have access to its properties, but when the detokeniser runs i get the error:

Detokenise Task Execution Completed [15:07:50]
C:\Source\1.2\Build\Detokenise.msbuild(27,3):
error : InvalidProjectFileException: The imported project "C:\Source\1.2\Build\Environments\.properties" was not found.
Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
C:\Source\1.2\Build\Detokenise.msbuild\r
C:\Source\1.2\Build\Detokenise.msbuild(27,3): error :

All works fine if i hard code it-
Any ideas how to solve this. I thought of doing some text replacement on the msbuild before i execute...

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

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

发布评论

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

评论(2

顾挽 2024-11-26 12:12:40

您可以尝试将此参数分配给本地属性:

<PropertyGroup Condition="'$(Env)'=='Prod'">
    <TargetEnv>Prod</TargetEnv>
</PropertyGroup>

<!-- add other environments as needed -->
<PropertyGroup Condition="'$(Env)'=='Test'">
    <TargetEnv>Test</TargetEnv>
</PropertyGroup>

<Import Project=".\Environments\$(TargetEnv).properties"/>

您还可以尝试将参数值括在引号中:

msbuild Detokenise.msbuild /p:"Env=Prod"

因为您的问题无法重现,所以它可能是示例代码中未显示的其他参数的副作用。

You could try to assign this parameter to a local property:

<PropertyGroup Condition="'$(Env)'=='Prod'">
    <TargetEnv>Prod</TargetEnv>
</PropertyGroup>

<!-- add other environments as needed -->
<PropertyGroup Condition="'$(Env)'=='Test'">
    <TargetEnv>Test</TargetEnv>
</PropertyGroup>

<Import Project=".\Environments\$(TargetEnv).properties"/>

You could also try to enclose your parameter value in quotes:

msbuild Detokenise.msbuild /p:"Env=Prod"

As is your problem can't be reproduced, so it may be a side effect of other parameters not shown in your sample code.

不离久伴 2024-11-26 12:12:40

我见过许多其他问题也发生了类似的问题:
Visual Studio 忽略 MSBuild 文件 (csproj) 自定义

I've seen a number of other questions where a similar problems was happening:
Visual Studio Ignoring MSBuild file (csproj) Customizations

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