Reputation: 9499
I have a VS 2010 solution that uses config transforms like so:
<Target Name="AfterBuild">
<TransformXml Condition="'$(IsDesktopBuild)' == 'false'" Source="Web.config" Transform="$(ProjectConfigTransformFileName)" Destination="$(PublishDir)\_PublishedWebsites\$(ProjectName)\Web.config" />
<Delete Files="$(PublishDir)\_PublishedWebsites\$(ProjectName)\Web.Debug.config" Condition="'$(IsDesktopBuild)' == 'false'" />
<Delete Files="$(PublishDir)\_PublishedWebsites\$(ProjectName)\Web.Release.config" Condition="'$(IsDesktopBuild)' == 'false'" />
<Delete Files="$(PublishDir)\_PublishedWebsites\$(ProjectName)\Web.Something.config" Condition="'$(IsDesktopBuild)' == 'false'" />
<Delete Files="$(PublishDir)\_PublishedWebsites\$(ProjectName)\Web.Else.config" Condition="'$(IsDesktopBuild)' == 'false'" />
<AspNetCompiler Condition="('$(IsDesktopBuild)' != 'false') AND ('$(MvcBuildViews)'=='true')" VirtualPath="temp" PhysicalPath="$(ProjectDir)\..\$(ProjectName)" />
<AspNetCompiler Condition="('$(IsDesktopBuild)' == 'false') AND ('$(MvcBuildViews)'=='true')" VirtualPath="temp" PhysicalPath="$(PublishDir)\_PublishedWebsites\$(ProjectName)" />
</Target>
This is in each website project (.csproj) in .sln.
When I run the v 4.0 MSBuild with a /p:PublishDir specified everything is fine. But when I run this as a Build Definition using Default template (GitTemplate.xaml) the folder for some reason resolves to $(ProjectDir)
, not the publish location. so the transform target is trying to copy files to the folder that doesn't exist ($(ProjectDir)\_PublishedWebsites\$(ProjectName)\Web.config
).
If I manually specify the /p:PublishDir to a STATIC location on disk, the build succeeds. How can I tell the MSBuild where the PublishDir actually is?
I am happy to edit the workflow to assign a variable or something, I just don't see how its possible.
I also tried specifying relative paths (e.g. /p:PublishDir="..\..\bin\\"
) and the team build agent variables (same as we have configured for build paths, e.g. /p:PublishDir="D:\$(BuildAgentId)\$(BuildDefinitionId)\bin\\"
) to no avail - it seems that the variables are not unwrapped and relative path doesn't work.
Upvotes: 0
Views: 291
Reputation: 3413
Add something like this before the AfterBuild target:
<PropertyGroup>
<PublishDir>PATH_TO_YOUR_PUBLISH_DIR</PublishDir>
</PropertyGroup>
You should be able to use relative paths without problem:
<PropertyGroup>
<PublishDir>..\..\bin\</PublishDir>
</PropertyGroup>
Remember that the path will be relative to the current project file.
If you want to override it from the command line you can add a condition like this:
<PropertyGroup>
<PublishDir Condition="'$(PublishDir)'==''">PATH_TO_YOUR_PUBLISH_DIR</PublishDir> <!-- This will be the default value -->
</PropertyGroup>
Then call MsBuild with /p:PublishDir="Your_New_Path" to override the default value.
If you have a VS solution you could use something like this:
<PropertyGroup>
<PublishDir Condition="'$(PublishDir)'==''">$(SolutionDir)PublishDir</PublishDir> <!-- This will be the default value -->
</PropertyGroup>
This will use the directory where the solution is placed as root and will create a "PublishDir" folder there.
This will work only if you have a solution, off course you could define a default value in case there's no solution:
<PropertyGroup>
<SolutionDir Condition="'$(SolutionDir)'=='' Or '$(SolutionDir)'=='*Undefined*'">Your_Default_SolutionDir</SolutionDir>
<PublishDir Condition="'$(PublishDir)'==''">$(SolutionDir)PublishDir</PublishDir> <!-- This will be the default value -->
</PropertyGroup>
Upvotes: 1