In my AfterBuild script I use the following method to upload the files to the deployment server:
<MSBuild.ExtensionPack.Communication.Ftp
TaskAction="UploadFiles"
Host="localhost"
FileNames="$(SomeFolder)\$(FileToUpload)"
UserName="myUserName"
UserPassword="myPassword"
RemoteDirectoryName="/" />
How can I load these credentials from a text file or an external source? What are the alternatives? I don't want to hard-code ftp credentials into my cproj files.
I used GranadaCoders method to answer my own question:
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="ReadAttribute" File="$(FTP_Credentials_File)" XPath="/parameters/setParameter[#name='host']/#value">
<Output PropertyName="FtpHost" TaskParameter="Value"/>
</MSBuild.ExtensionPack.Xml.XmlFile>
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="ReadAttribute" File="$(FTP_Credentials_File)" XPath="/parameters/setParameter[#name='username']/#value">
<Output PropertyName="FtpUserName" TaskParameter="Value"/>
</MSBuild.ExtensionPack.Xml.XmlFile>
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="ReadAttribute" File="$(FTP_Credentials_File)" XPath="/parameters/setParameter[#name='password']/#value">
<Output PropertyName="FtpPassword" TaskParameter="Value"/>
</MSBuild.ExtensionPack.Xml.XmlFile>
<Message Text="Attempting to uploade $(GeneratedZipFile) to $(FtpHost) as read from $(FTP_Credentials_File) ..." Importance="high" />
<MSBuild.ExtensionPack.Communication.Ftp TaskAction="UploadFiles" Condition="Exists('$(FTP_Credentials_File)')" Host="$(FtpHost)" FileNames="$(PublicFolderToDropZip)\$(GeneratedZipFile)" UserName="$(FtpUserName)" UserPassword="$(FtpPassword)" RemoteDirectoryName="/" />
Put the values in an external xml file.
Read the values from the xml file into a variable.
Parameters.xml
<?xml version="1.0" encoding="utf-8"?>
<parameters>
<setParameter name="LineNumber1" value="PeanutsAreCool" />
<setParameter name="LineNumber2" value="" />
</parameters>
MyMsbuild_MsBuildExtensions.proj
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapped">
<Import Project="$(MSBuildExtensionsPath)\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks"/>
<PropertyGroup>
<!-- Always declare some kind of "base directory" and then work off of that in the majority of cases -->
<WorkingCheckout>.</WorkingCheckout>
</PropertyGroup>
<Target Name="AllTargetsWrapped">
<CallTarget Targets="ReadXmlPeekValue" />
</Target>
<Target Name="ReadXmlPeekValue">
<!-- ReadAttribute -->
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="ReadAttribute" File="$(WorkingCheckout)\Parameters.xml" XPath="/parameters/setParameter[#name='LineNumber1']/#value">
<Output PropertyName="MyValue1" TaskParameter="Value"/>
</MSBuild.ExtensionPack.Xml.XmlFile>
<Message Text="MyValue1 = $(MyValue1)"/>
</Target>
</Project>
OR
MyMsbuild_WithCommunityTasks.proj
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapped">
<!--
<UsingTask AssemblyFile="$(ProgramFiles)\MSBuild\MSBuild.Community.Tasks.dll" TaskName="Version"/>
-->
<Import Project="$(MSBuildExtensionsPath32)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<PropertyGroup>
<!-- Always declare some kind of "base directory" and then work off of that in the majority of cases -->
<WorkingCheckout>.</WorkingCheckout>
</PropertyGroup>
<Target Name="AllTargetsWrapped">
<CallTarget Targets="ReadXmlPeekValue" />
</Target>
<Target Name="ReadXmlPeekValue">
<!-- you do not need a namespace for this example, but I left it in for future reference -->
<XmlPeek Namespaces="<Namespace Prefix='peanutNamespace' Uri='http://schemas.microsoft.com/developer/msbuild/2003'/>"
XmlInputPath=".\Parameters.xml"
Query="/parameters/setParameter[#name='LineNumber1']/#value">
<Output TaskParameter="Result" ItemName="Peeked" />
</XmlPeek>
<Message Text="#(Peeked)"/>
<XmlPeek Namespaces="<Namespace Prefix='peanutNamespace' Uri='http://schemas.microsoft.com/developer/msbuild/2003'/>"
XmlInputPath=".\Parameters.xml"
Query="/parameters/setParameter[#name='LineNumber1']/#value">
<Output TaskParameter="Result" PropertyName="PeekedSingle" />
</XmlPeek>
<Message Text="PeekedSingle = $(PeekedSingle) "/>
</Target>
</Project>
EDIT:
You can add some basic error checking for the values.
See URL here:
http://tutorials.csharp-online.net/MSBuild:_By_Example%E2%80%94Dealing_with_MSBuild_Errors
Short example.. note the condition..and how it checks for an empty string.
<Error Text="Unable to connect to webserver" Code="Deploy" Condition=" '$(WebURL)' == '' "/>
Related
I have following directories (for example)
./dirA/file1
./dirA/dir/file2
./dirB/file3
./dirB/dir/file4
./dirC/file5
And I want to have them copied to something different, like:
./dirA_renamed/file1
./dirA_renamed/dir/file2
./dirB_renamed_differently/file3
./dirB_renamed_differently/dir/file4
./dirC_renam/file5
The list of directories and their new names is something that does not change very often, but I'd like to use only one Copy.
I tried following:
<ItemGroup>
<ToCopy Include=".\dirA">
<OutputDirName>dirA_renamed</OutputDirName>
</ToCopy>
<ToCopy Include=".\dirB">
<OutputDirName>dirB_renamed_differently</OutputDirName>
</ToCopy>
<ToCopy Include=".\dirC">
<OutputDirName>dirC_renam</OutputDirName>
</ToCopy>
</ItemGroup>
......
<CreateItem Include="%(ToCopy.Directory)\**\*.*">
<Output TaskParameter="Include" ItemName="FilesToCopy" />
</CreateItem>
<Copy SourceFiles="#(FilesToCopy)" DestinationFolder="#(FilesToCopy->'%(OutputDirName)')" />
But nothing happens. If I output FilesToCopy, it is empty. What am I doing wrong?
The hard coded way is the one I know, but I know that you can use parameters, I just haven't figure it out completely yet, to give you a working sample.
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
ToolsVersion="4.0" DefaultTargets="Build">
<PropertyGroup>
<RootDir>C:\DevDir</RootDir>
<SourceA>dirA</SourceA>
<SourceB>dirB</SourceB>
<SourceC>dirC</SourceC>
<RenameA>dirA_renamed</RenameA>
<RenameB>dirB_renamed_differently</RenameB>
<RenameC>dirC_renam</RenameC>
</PropertyGroup>
<Target Name="CopyDirTest" >
<ItemGroup>
<SourceDirA Include="$(RootDir)$(SourceA)\"/>
<SourceDirB Include="$(RootDir)$(SourceB)\" />
<SourceDirC Include="$(RootDir)$(SourceC)\" />
</ItemGroup>
<ItemGroup>
<SourceAFiles Include="$(RootDir)$(SourceA)\**\*.*" />
<SourceBFiles Include="$(RootDir)$(SourceB)\**\*.*" />
<SourceCFiles Include="$(RootDir)$(SourceC)\**\*.*" />
<SourceAllFiles Include="#(SourceAFiles);#(SourceBFiles);#(SourceCFiles)" />
</ItemGroup>
<CreateItem Include="#(SourceAFiles->Replace($(SourceA), $(RenameA)))">
<Output TaskParameter="Include" ItemName="RenamedSourceA" />
</CreateItem>
<CreateItem Include="#(SourceBFiles->Replace($(SourceB), $(RenameB)))">
<Output TaskParameter="Include" ItemName="RenamedSourceB" />
</CreateItem>
<CreateItem Include="#(SourceCFiles->Replace($(SourceC), $(RenameC)))">
<Output TaskParameter="Include" ItemName="RenamedSourceC" />
</CreateItem>
<ItemGroup>
<RenamedAllFiles Include="#(RenamedSourceA);#(RenamedSourceB);#(RenamedSourceC)" />
</ItemGroup>
<Message Text="%(SourceAllFiles.Identity)" Importance="high" />
<Message Text="%(RenamedAllFiles.Identity)" Importance="high" />
<Copy SourceFiles="#(SourceAllFiles)" DestinationFiles="#(RenamedAllFiles)" />
</Target>
</Project>
I attempt to execute the following target but ends up with circular dependency error. I do have a stop condition $(Value) > 0 in target Recursive:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<Target Name="Recursive" Condition="$(Value) > 0">
<PropertyGroup>
<Value>$([MSBuild]::Subtract($(Value), 1))</Value>
</PropertyGroup>
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Display" />
</Target>
<Target Name="Display">
<Message Text="Value: $(Value)" />
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Recursive" />
</Target>
<PropertyGroup>
<Value>10</Value>
</PropertyGroup>
<Target Name="Build">
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Display" />
</Target>
</Project>
Your stop condition is fine, but you forgot to pass the recalculated Value property into the next recursion. Change your Recursive target like this:
<Target Name="Recursive" Condition="$(Value) > 0">
<PropertyGroup>
<Value>$([MSBuild]::Subtract($(Value), 1))</Value>
</PropertyGroup>
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Display"
Properties="Value=$(Value)" />
</Target>
I am trying to run multiple commands on a list of files based on a pattern (all files of form *.config under sub directories of a given directory), like so:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="BuildSolution" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TransformXml"
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<TransformConfiguration>Release</TransformConfiguration>
<PublishFolder>$(OutDir)_PublishedWebsites</PublishFolder>
</PropertyGroup>
<Target Name="BuildSolution">
<MSBuild Projects="$(MSBuildProjectDirectory)\SolutionName.sln"
ContinueOnError="false"
Properties="PublishProfile=$(TransformConfiguration);DeployOnBuild=true" />
</Target>
<ItemGroup>
<ConfigFiles Include="$(PublishFolder)\**\*.config" />
</ItemGroup>
<Target Name="TransformWebConfig" AfterTargets="BuildSolution"
Condition="'#(ConfigFiles)'!=''"
Outputs="%(ConfigFiles.Identity)">
<PropertyGroup>
<ConfigFile>%(ConfigFiles.Identity)</ConfigFile>
<BackupFile>$([System.IO.Path]::ChangeExtension($(ConfigFile),".Source.config"))</BackupFile>
<TransformFile>$([System.IO.Path]::ChangeExtension($(ConfigFile),$(TransformConfiguration) + ".Source.config"))</TransformFile>
</PropertyGroup>
<Message Text="$(ConfigFile)" />
<Message Text="$(BackupFile)" />
<Message Text="$(TransformFile)" />
<Copy SourceFiles="$(ConfigFile)"
DestinationFiles="$(BackupFile)" />
<Exec Command="attrib -r $(ConfigFile)" />
<TransformXml Source="$(BackupFile)"
Transform="$(TransformFile)"
Destination="$(ConfigFile)"
StackTrace="false" />
</Target>
</Project>
However, the batch processing of the matching files is not performed.
From outputs I have added I see that the property $(PublishFolder) points to the correct directory, however, the item #(ConfigFiles) is left empty.
I also tried manually listing the directory names and configuration file names like so:
<ItemGroup>
<Sites Include="Site1" />
<Sites Include="Site2" />
</ItemGroup>
<ItemGroup>
<ConfigFiles Include="Web" />
<ConfigFiles Include="NLog" />
</ItemGroup>
<Target Name="TransformWebConfig" AfterTargets="BuildSolution">
<PropertyGroup>
<SiteConfigFile>$(PublishFolder)\%(Sites.Identity)\%(ConfigFiles.Identity)</SiteConfigFile>
</PropertyGroup>
<Message Text="$(SiteConfigFile)" />
<Copy SourceFiles="$(SiteConfigFile).config"
DestinationFiles="$(SiteConfigFile).Source.config"/>
<Exec Command="attrib -r $(SiteConfigFile).config" />
<TransformXml Source="$(SiteConfigFile).Source.config"
Transform="$(SiteConfigFile).$(TransformConfiguration).config"
Destination="$(SiteConfigFile).config"
StackTrace="false" />
</Target>
However, in this case, the transform is only applied on one file in one site.
Any idea what to do to get this working?
Similar questions and MSDN references I have gone through:
MSBUild: Copy files with a name based on the original (following a pattern)
MSBuild multiple outputpath
How to invoke the same msbuild target twice with different parameters from within msbuild project file itself
msbuild array iteration
http://msdn.microsoft.com/en-us/library/ms171454.aspx
Edit:
Moving the ItemGroup under the task enabled reading the file list after the files were created, however, now only the first file from the list is transformed:
<ItemGroup>
<ConfigFiles Include="$(PublishFolder)\**\Web.config;$(PublishFolder)\**\NLog.config"
Exclude="$(PublishFolder)\**\Packages.config;$(PublishFolder)\**\*.*.config;$(PublishFolder)\**\bin\*.config" />
</ItemGroup>
<PropertyGroup>
<ConfigFile>%(ConfigFiles.Identity)</ConfigFile>
<BackupFile>$([System.IO.Path]::ChangeExtension($(ConfigFile),".Source.config"))</BackupFile>
<TransformFilePrefix>$([System.String]::Concat($(TransformConfiguration), ".config"))</TransformFilePrefix>
<TransformFile>$([System.IO.Path]::ChangeExtension($(ConfigFile), $(TransformFilePrefix)))</TransformFile>
</PropertyGroup>
<Message Text="$(PublishFolder)" />
<Message Text="#(ConfigFiles)" />
<Message Text="$(ConfigFile)" />
<Message Text="$(BackupFile)" />
<Message Text="$(TransformFile)" />
<Copy SourceFiles="$(ConfigFile)"
DestinationFiles="$(BackupFile)" />
<Exec Command="attrib -r $(ConfigFile)" />
<TransformXml Source="$(BackupFile)"
Transform="$(TransformFile)"
Destination="$(ConfigFile)"
StackTrace="false" />
Found the solution:
Create one target for creating the item group:
<Target Name="ListWebConfigs" AfterTargets="BuildSolution">
<ItemGroup>
<ConfigFiles Include="$(PublishFolder)\**\Web.config;$(PublishFolder)\**\NLog.config"
Exclude="$(PublishFolder)\**\Packages.config;$(PublishFolder)\**\*.*.config;$(PublishFolder)\**\bin\*.config" />
</ItemGroup>
<Message Text="$(PublishFolder)" />
<Message Text="#(ConfigFiles)" />
</Target>
Then another for the actual transforms:
<!-- \x to prevent MSBuild from skipping "because all output files are up-to-date" -->
<Target Name="TransformWebConfig" AfterTargets="ListWebConfigs" Inputs="#(ConfigFiles)" Outputs="%(ConfigFiles.Identity)\x">
<PropertyGroup>
<ConfigFile>%(ConfigFiles.Identity)</ConfigFile>
<BackupFile>$([System.IO.Path]::ChangeExtension($(ConfigFile),".Source.config"))</BackupFile>
<TransformFilePrefix>$([System.String]::Concat($(TransformConfiguration), ".config"))</TransformFilePrefix>
<TransformFile>$([System.IO.Path]::ChangeExtension($(ConfigFile), $(TransformFilePrefix)))</TransformFile>
</PropertyGroup>
<Message Text="$(PublishFolder)" />
<Message Text="#(ConfigFiles)" />
<Message Text="$(ConfigFile)" />
<Message Text="$(BackupFile)" />
<Message Text="$(TransformFile)" />
<Copy SourceFiles="$(ConfigFile)" DestinationFiles="$(BackupFile)" />
<Exec Command="attrib -r $(ConfigFile)" />
<TransformXml Source="$(BackupFile)"
Transform="$(TransformFile)"
Destination="$(ConfigFile)"
StackTrace="false" />
</Target>
I'm trying to transform web.configs as part of a build process through MSBuild, which is fine; but dealing with multiple web.configs in the same solution is causing problems.
The code we are using at the moment extracts web.config specific information and passes it to a transform target, both of these operations are bundled in a DependsOnTargets target:
<Target Name="ExtractWebConfigParams_1">
<!-- Get webConfig1 info -->
</Target>
<Target Name="TransformWebConfig_1">
<TransformXml Source="%(webConfig1).Web.config"
Transform="%(webConfig1).Web.Stage.config"
Destination="%(webConfig1).Web.config"
StackTrace="$(StackTraceEnabled)" />
</Target>
<Target Name="ExtractWebConfigParams_2">
<!-- Get webConfig2 info -->
</Target>
<Target Name="TransformWebConfig_2">
<TransformXml Source="%(webConfig2).Web.config"
Transform="%(webConfig2).Web.Stage.config"
Destination="(webConfig2).Web.config"
StackTrace="$(StackTraceEnabled)" />
</Target>
<Target
Name="Transform_1"
DependsOnTargets="ExtractWebConfigParams_1;
TransformWebConfig_1;">
</Target>
<Target
Name="Transform_2"
DependsOnTargets="ExtractWebConfigParams_2;
TransformWebConfig_2;">
</Target>
Our solution may contain up to 5 different web.configs, so there would have to be an extract, transform and DependsOnTargets target for every one of them.
I can't see a way of getting around using multiple extract targets but does anyone know if there's a way to call the transform target with different parameters instead of making an entirely new target everytime?
You can write a separate .msbuild (.proj) file as "reusable logic".
I have a "zip up website" common logic I'll post below.
My example was about zipping up an asp.net website, but encapsulating the rules about which files to ignore (.csproj for example).......and also have a few "hooks" for ignoring some files. Like the "images" directory, ours was HUGE, so I didn't want to zip that up every time.
My example is not directly related to your need. Its the idea that is important.
Encapsulate all your logic into one file, and pass parameters to it.
I include the .proj file in the Main.proj file. Then pass parameters to it.
ONE CAVEAT. Relative directories do NOT work in the sub .proj file if it is located anywhere besides the same directory as the Main.proj file.
Ala, you cannot set a directory property to something like ".\bin\", you have to figure out the full path BEFORE you call the sub-proj file and pass the full folder name. Is this example, "c:\myfolder\mysolution\myproject1\bin" ... aka, whatever f
Code to put in the "outside" Main.proj file:
<Target Name="ZipItUpUsingCommonLogic">
<Message Text=" " />
<Message Text=" About to Call External MSBUILD File " />
<Message Text=" " />
<MSBuild Projects="..\..\CommonLogicMsBuildStuff\WebSiteZippingCommonLogic.proj" Targets="WebSiteZippingAllTargetsWrapper" Properties="WebSiteFolderFullPath=c:\workstuff\mywebsolution;OutputFolderFullPath=c:\workstuff\buildoutputs;WebSiteZipFileNameNonConfig=MyNonConfigFiles$(Configuration).zip;WebSiteZipFileNameConfigFiles=MyWebSiteConfigFiles$(Configuration).zip;RevisionNumber=333;IgnoreFolder1=c:\workstuff\mywebsolution\images" />
</Target>
Code for a file named "WebSiteZippingCommonLogic.proj":
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="WebSiteZippingAllTargetsWrapper">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<Import Project="$(MSBuildExtensionsPath)\ExtensionPack\MSBuild.ExtensionPack.tasks" />
<!-- There was an issue with the xsl/document(path) function......this help address the issue. -->
<Target Name="WebSiteZippingAllTargetsWrapper">
<CallTarget Targets="ShowParameters" />
<CallTarget Targets="ValidateParameters" />
<CallTarget Targets="ZipTheWebSite" />
</Target>
<Target Name="ValidateParameters">
<Error Text="The WebSiteFolderFullPath property was not passed in correctly." Condition="'$(WebSiteFolderFullPath)' == ''" />
<Error Text="The OutputFolderFullPath property was not passed in correctly." Condition="'$(OutputFolderFullPath)' == ''" />
<Error Text="The WebSiteZipFileNameNonConfig property was not passed in correctly." Condition="'$(WebSiteZipFileNameNonConfig)' == ''" />
<Error Text="The WebSiteZipFileNameConfigFiles property was not passed in correctly." Condition="'$(WebSiteZipFileNameConfigFiles)' == ''" />
<!--<Error Text="The RevisionNumber property was not passed in correctly." Condition="'$(RevisionNumber)' == ''" />-->
</Target>
<Target Name="ShowParameters">
<Message Text=" WebSiteFolderFullPath = $(WebSiteFolderFullPath)" />
<Message Text=" OutputFolderFullPath = $(OutputFolderFullPath)" />
<Message Text=" WebSiteZipFileNameNonConfig = $(WebSiteZipFileNameNonConfig)" />
<Message Text=" WebSiteZipFileNameConfigFiles = $(WebSiteZipFileNameConfigFiles)" />
<Message Text=" IgnoreFolder1 = $(IgnoreFolder1)" />
<Message Text=" IgnoreFolder2 = $(IgnoreFolder2)" />
<Message Text=" IgnoreFolder3 = $(IgnoreFolder3)" />
<Message Text=" " />
<Message Text=" " />
</Target>
<Target Name="ZipTheWebSite" DependsOnTargets="ValidateParameters">
<ItemGroup>
<WebSiteExcludeFiles Include="$(WebSiteFolderFullPath)\**\*.sln" />
<WebSiteExcludeFiles Include="$(WebSiteFolderFullPath)\**\*.vbproj" />
<WebSiteExcludeFiles Include="$(WebSiteFolderFullPath)\**\*.csproj" />
<WebSiteExcludeFiles Include="$(WebSiteFolderFullPath)\**\*.config" />
<WebSiteExcludeFiles Include="$(WebSiteFolderFullPath)\.svn\**\*.*" />
<WebSiteExcludeFiles Include="$(WebSiteFolderFullPath)\obj\**\*.*" />
<WebSiteExcludeFiles Include="$(WebSiteFolderFullPath)\**\.svn\**" />
<WebSiteExcludeFiles Include="$(WebSiteFolderFullPath)**\.svn\**\*.*" />
<WebSiteExcludeFiles Include="$(IgnoreFolder1)\**\*.*" Condition="'$(IgnoreFolder1)' != ''" />
<WebSiteExcludeFiles Include="$(IgnoreFolder2)\**\*.*" Condition="'$(IgnoreFolder2)' != ''" />
<WebSiteExcludeFiles Include="$(IgnoreFolder3)\**\*.*" Condition="'$(IgnoreFolder3)' != ''" />
</ItemGroup>
<ItemGroup>
<WebSiteNonConfigIncludeFiles Include="$(WebSiteFolderFullPath)\**\*.*" Exclude="#(WebSiteExcludeFiles)">
</WebSiteNonConfigIncludeFiles>
</ItemGroup>
<MSBuild.Community.Tasks.Zip Files="#(WebSiteNonConfigIncludeFiles)" ZipFileName="$(OutputFolderFullPath)\$(WebSiteZipFileNameNonConfig)" WorkingDirectory="$(WebSiteFolderFullPath)\" />
<ItemGroup>
<WebSiteConfigIncludeFiles Include="$(WebSiteFolderFullPath)\**\*.config">
</WebSiteConfigIncludeFiles>
</ItemGroup>
<MSBuild.Community.Tasks.Zip Files="#(WebSiteConfigIncludeFiles)" ZipFileName="$(OutputFolderFullPath)\$(WebSiteZipFileNameConfigFiles)" WorkingDirectory="$(WebSiteFolderFullPath)\" />
<Message Text=" " />
<Message Text=" " />
</Target>
</Project>
If you don't want to encapsulate rules into a separate file, then you may be looking for this:
http://sstjean.blogspot.com/2006/09/how-to-get-msbuild-to-run-complete.html
However, I find the constant "condition-checks" annoying, which is why I went to the "by file" method, which I describe above.
I'm going to copy/paste his example here, just in case his blog ever goes down.
Remember "gotdotnet.com" ??
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Package Include="CommonWebSetup.ism">
<PackagerType>IS</PackagerType>
<SetupProjFolder>CommonWebSetup</SetupProjFolder>
<ISProductConfig>Server</ISProductConfig>
<ISReleaseConfig>Release</ISReleaseConfig>
</Package>
<Package Include="CommonClientSetup.vdproj">
<PackagerType>VS</PackagerType>
<SetupProjFolder>CommonClientSetup</SetupProjFolder>
<ISProductConfig>Client</ISProductConfig>
<ISReleaseConfig>Release</ISReleaseConfig>
</Package>
</ItemGroup>
<Target Name="Test" Outputs="%(Package.Identity)" >
<Message Text="Removing read-only flag for %(Package.Identity)" Importance="High" />
<Message Text="Setting Environment variable for %(Package.Identity)" Importance="High" />
<Message Condition=" '%(Package.PackagerType)' == 'IS' "
Text="Running InstallShield for %(Package.Identity)" Importance="High" />
<Message Condition=" '%(Package.PackagerType)' == 'VS' "
Text="Running DevEnv.exe for %(Package.Identity)" Importance="High" />
</Target>
I would like to add content to my web application depending on the configuration. I have declared the target in the initials target and the target looks like this :
<Target Name="ApplicationNameDefinition" Outputs="$(MashupName)">
<MSBuild.ExtensionPack.Framework.TextString TaskAction="StartsWith" String1="$(ConfigurationName)" String2="Config1">
<Output TaskParameter="Result" PropertyName="isConfig1" />
</MSBuild.ExtensionPack.Framework.TextString>
<MSBuild.ExtensionPack.Framework.TextString TaskAction="StartsWith" String1="$(ConfigurationName)" String2="Config2">
<Output TaskParameter="Result" PropertyName="isConfig2" />
</MSBuild.ExtensionPack.Framework.TextString>
<MSBuild.ExtensionPack.Framework.TextString TaskAction="StartsWith" String1="$(ConfigurationName)" String2="Config3">
<Output TaskParameter="Result" PropertyName="isConfig3" />
</MSBuild.ExtensionPack.Framework.TextString>
<MSBuild.ExtensionPack.Framework.TextString TaskAction="StartsWith" String1="$(ConfigurationName)" String2="Config4">
<Output TaskParameter="Result" PropertyName="isConfig4" />
</MSBuild.ExtensionPack.Framework.TextString>
<Error Condition=" !$(isConfig1) And !$(isConfig2) And !$(isConfig3) And !$(isConfig4) " Text="Configuration $(ConfigurationName) Inconnue" />
<PropertyGroup>
<MashupName Condition="$(isConfig1)">App1</MashupName>
<MashupName Condition="$(isConfig2)">App2</MashupName>
<MashupName Condition="$(isConfig3)">App3</MashupName>
<MashupName Condition="$(isConfig4)">App4</MashupName>
</PropertyGroup>
<Error Condition="'$(MashupName)'==''" Text="Configuration $(MashupName) Inconnue" />
<ItemGroup >
<Content Condition=" '$(MashupName)'!='' " Include="App_Themes\$(MashupName)\**" />
</ItemGroup>
However, the content is not added to the project. Any Idea ?
Thanks.
Actually this works in msbuild, but not in Visual Studio which has some cache with csproj files...