0

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...

Filburt
  • 17,626
  • 12
  • 64
  • 115
James Woolfenden
  • 6,498
  • 33
  • 53

2 Answers2

2

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.

Filburt
  • 17,626
  • 12
  • 64
  • 115
  • Thanks for the answer but thats pretty mcuh how it works now and your method usually works just fine for me, it seems to be something about loading the task file causes the issue. I can message out the property and its correct but pass it to the task and it reverts to its preprocessed value. – James Woolfenden Jul 26 '11 at 07:45
  • You can partially solve this issue by using the property CommandLineValues of the task – James Woolfenden Jul 31 '12 at 14:38
0

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

Community
  • 1
  • 1
James Woolfenden
  • 6,498
  • 33
  • 53