I want to delete some image resources depending on what build I'm releasing using MsDeploy.
I have three builds for different clients which are basicly another theme and a lot of configuration transforms to setup their environments correctly.
I donĀ“t want to include the image resources for client1 when deploying to client2.
Been using this as a reference for making my first stumbling steps into customizing msdeploy and it works good but I have no idea what variable to get the configuration name.
In pseudo code:
if $configurationName == "client1"
exclude dirs gfx/client2 and gfx/client3
if $configurationName == "client2"
exclude dirs gfx/client1, gfx/client3
and so on...
May be its even possible to exclude all and then include just the one which is needed?
I have posted an entry on my blog about this at http://sedodream.com/2010/08/15/WebDeploymentToolMSDeployHowToExcludeFilesFromPackageBasedOnConfiguration.aspx. Here is the summary:
You use the same approach as in my previous answer, ExcludeFromPackageFiles but you just put a condition on it. So if you have files under scripts folder with 'debug' in the file name that you want to exclude from any package which not built under debug configuration the way you do it is
<ItemGroup Condition=" '$(Configuration)'!='Debug' ">
<ExcludeFromPackageFiles Include="scripts\**\*debug*" />
</ItemGroup>
More details on my blog, but its a simple mod to the previous approach.
Thanks for both your answers. I fixed everything now, struggled alot with including a build and migration for my database (migrator.net) but I cheated and did it through the runcommand instead.
I thought I post my whole deployment process here so people who read this post might learn from all my misstakes.
The basic steps are:
Web.config transforms to make sure all settings are correct for each of the clients
Backup of webserver files and database at the production server
Exclude all gfx directories for all clients
Include the gfx dir which is wanted by this client
Include extra binares and license-files which are not referenced by the project correclty
Migrate the database to the current revision
Webdeploy all the new files
Deploy.proj, imported by <Import Project="Deploy.csproj" /> at the last line of the webproject project file:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
ExcludeAllGfx;
Client1Backup;
Client1Include;
Client1Migrate;
CollectBinFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<Target Name="ExcludeAllGfx" BeforeTargets="ExcludeFilesFromPackage">
<ItemGroup>
<ExcludeFromPackageFiles Include="gfx\client1\**\*.*">
<FromTarget>Project</FromTarget>
</ExcludeFromPackageFiles>
<ExcludeFromPackageFiles Include="gfx\client2\**\*.*">
<FromTarget>Project</FromTarget>
</ExcludeFromPackageFiles>
<ExcludeFromPackageFiles Include="gfx\client3\**\*.*">
<FromTarget>Project</FromTarget>
</ExcludeFromPackageFiles>
</ItemGroup>
<Message Text="ExcludeFromPackageFiles: #(ExcludeFromPackageFiles)" Importance="high" />
</Target>
<Target Name="CollectBinFiles">
<ItemGroup>
<_CustomFiles Include="..\IncludeBin\Telerik\Telerik.ReportViewer.WebForms.dll" />
<_CustomFiles Include="..\IncludeBin\Telerik\Telerik.Reporting.dll" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>Bin\%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
<Target Name="Client1Migrate" Condition="'$(Configuration)|$(Platform)' == 'Release Client1|AnyCPU'">
<Exec Command=""..\MigratorProject\Bats\Client1.bat"" ContinueOnError="false" />
</Target>
<Target Name="Client1Include" Condition="'$(Configuration)|$(Platform)' == 'Release Client1|AnyCPU'">
<ItemGroup>
<_CustomFilesClient1 Include="gfx\Client1\**\*.*" Exclude="gfx\Client1\**\.svn\**\*.*">
<FromTarget>Project</FromTarget>
</_CustomFilesClient1>
<FilesForPackagingFromProject Include="%(_CustomFilesClient1.Identity)">
<DestinationRelativePath>gfx\client1\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
<Target Name="Client1Backup" Condition="'$(Configuration)|$(Platform)' == 'Release Client1|AnyCPU'">
<Exec Command=""C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe" -verb:sync -source:contentPath="page of client1",computerName=http://10.8.1.1/MsDeployAgentService2,encryptPassword=pass -dest:package=c:\Backups\deployments\client1.zip,computerName=http://10.8.1.1/MsDeployAgentService2,encryptPassword=pass" ContinueOnError="false" />
<Exec Command=""C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe" -verb:sync -source:runCommand='C:\Backups\deployments\scripts\backup.cmd client1',waitInterval=20000 -dest:auto,computerName=http://10.8.1.1/MsDeployAgentService2,encryptPassword=pass" ContinueOnError="false" />
</Target>
</Project>
Backup.cmd:
#echo off
sqlcmd -v name=%1 -S . -i "C:\Backups\deployments\scripts\backupdb.sql"
C:\Backups\deployments\scripts\stampme "C:\Backups\deployments\%1.zip"
backupdb.sql:
DECLARE #name NVARCHAR(50) -- database name
DECLARE #path NVARCHAR(256) -- path for backup files
DECLARE #fileName NVARCHAR(256) -- filename for backup
DECLARE #fileDate NVARCHAR(20) -- used for file name
SET #name = '$(name)'
SET #path = 'C:\Backups\deployments\'
SELECT #fileDate = REPLACE(REPLACE(CONVERT(VARCHAR(50),GETDATE(),120),':','-'), ' ', '#')
SET #fileName = #path + #name + '_' + #fileDate + '.BAK'
BACKUP DATABASE #name TO DISK = #fileName;
stampme.bat: http://ss64.com/nt/syntax-stampme.html
Hope anyone gets some help and examples from this entry.
You can extend Sayed's examples using the Condition attribute on your ItemGroup, and the $(Configuration) property.
e.g.:
<ItemGroup>
<Content Include="a.jpeg" Condition=" '$(Configuration)' == 'Client1' " />
</ItemGroup>
Related
I am looking for a way to run my defined Target only once per build process and not for every project that gets build.
I have defined the following in Directory.Build.props
<Target Name="MyTarget" AfterTargets="AfterBuild" >
<Message Text="Hello World!!!" Importance="High" />
</Target>
Should only run once no matter how many projects the msbuild process is building, currently it happens for each project.
It shouldn't matter if I hit (Re-)Build Soltution or (Re-)Build [ProjectName] or hit F5 in Visual Studio, as long any build happens I want to exectue MyTarget only once.
Just answer this situation:
If my guess is right, pure msbuild function is not enough and you have to use a external file to help it work.
create a file called test.txt on the solution folder and write 0 in the txt file.
Then, modify your Directory.Build.props like this:
<Project>
<PropertyGroup>
<Record></Record>
</PropertyGroup>
<ItemGroup>
<File Include="..\test.txt"></File>
</ItemGroup>
<Target Name="GetConditionValue" BeforeTargets="PrepareForBuild">
<ReadLinesFromFile File="#(File)">
<Output TaskParameter="Lines" PropertyName="Record"/>
</ReadLinesFromFile>
</Target>
<Target Name="MyTarget" AfterTargets="Build" Condition="'$(Record)'=='0'">
<WriteLinesToFile File="#(File)" Lines="2" Overwrite="true"></WriteLinesToFile>
<Message Text="Hello World!!!" Importance="High" />
</Target>
</Project>
When you start a new build process, you should clear the test.txt file to 0 to make a new start.
I am working on WiX Setup V3 project in Visual Studio 2019. I have to make this working in Visual Studio as well as from MSBuild (in Jenkins). I have authored custom target file which will be included in this project. Following is the markup of the custom target file. I cannot use the HeatDirectory task, since it lacks some flags like svb6. Hence I am using Exec command for Heat execution.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DefineConstants>HeatFldrPath=$(FilePath);ProductVersion=$(PVersion);BuildNumber=$(BldNum)</DefineConstants>
<OutputName>$(MSIName)</OutputName>
<OutputPath>$(MSIPath)</OutputPath>
<SuppressPdbOutput>True</SuppressPdbOutput>
</PropertyGroup>
<PropertyGroup>
<WixBinPath>$(SolutionDir)\Build\wix\</WixBinPath>
<WixToolPath>$(WixBinPath)\</WixToolPath>
<WixTargetsPath>$(WixToolPath)Wix.targets</WixTargetsPath>
<WixTasksPath>$(WixToolPath)wixtasks.dll</WixTasksPath>
</PropertyGroup>
<ItemGroup>
<WixExtension Include="WixUtilExtension">
<HintPath>lib\WixUtilExtension.dll</HintPath>
<Name>WixUtilExtension</Name>
</WixExtension>
<WixExtension Include="WixUIExtension">
<HintPath>lib\WixUIExtension.dll</HintPath>
<Name>WixUIExtension</Name>
</WixExtension>
<WixExtension Include="WixMsmqExtension">
<HintPath>lib\WixMsmqExtension.dll</HintPath>
<Name>WixMsmqExtension</Name>
</WixExtension>
<WixExtension Include="WixIIsExtension">
<HintPath>lib\WixIIsExtension.dll</HintPath>
<Name>WixIIsExtension</Name>
</WixExtension>
</ItemGroup>
<Target Name="HeatTarget" BeforeTargets="Build">
<Exec Command='"$(WixToolPath)\heat.exe" dir $(HeatFldrPath) -cg UserFeatureFiles -dr APP_DIR -gg -g1 -sfrag -sw -svb6 -srd -sreg -ke -var var.HeatFldrPath -out "Content\UserFiles.wxs"' />
</Target>
</Project>
I need to make this configurable for the following parameters:
Product Version (for use in Candle command)
Build Number (This will be added to the Product Version)
Heat Directory Path
MSI Name (This will have Version along with Build Number concatenated
to it)
MSI Path (I don't want this to be bin\$(Configuration)\en-us, rather
a custom directory I specify)
My custom targets file will be imported to the .wixproj file and nothing else will be changed in the .wixproj file.
If I use DefineConstants in my custom targets file, it works with MSBuild, but not with Visual Studio. I am having a hard time passing these as parameters and getting my MSI to build from both Visual Studio and MSBuild. I tried passing $(FilePath), $(PVersion) and $(BldNum) from project properties, but no luck. I cannot hard code these values in .targets or .wixproj file, since they have to be run from both Visual Studio and MSBuild. Also, I am not able to pass OutputName and OutputPath from Visual Studio. Can anyone please help me?
PFB the wixproj file.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build"
InitialTargets="EnsureWixToolsetInstalled"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == ''
">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>3.10</ProductVersion>
<ProjectGuid>{9ecbe76b-ecc4-4a17-bc8b-f2224421f616}</ProjectGuid>
<SchemaVersion>2.0</SchemaVersion>
<OutputName>My.Custom.MSI</OutputName>
<OutputType>Package</OutputType>
<PublishDir>..\HeatFolder</PublishDir>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==
'Debug|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>Debug;HeatFldrPath=$(PublishDir)</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==
'Release|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<WixVariables>$(FilePath)=$(ProjectDir)HeatFolder;$(PVersion)="1.1.0.1"
</WixVariables>
<DefineConstants>HeatFldrPath=$(FilePath);ProductVersion=1.1.0.1;BuildNumber=$
(BldNum)</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Full-
Release|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>Release;HeatFldrPath=$(PublishDir)</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="Content\GlobalCustomActions.wxs" />
<Compile Include="Content\GlobalExitDlg.wxs" />
<Compile Include="Content\GlobalFatalError.wxs" />
<Compile Include="Content\GlobalInstallDlg.wxs" />
<Compile Include="Content\GlobalLicenseAgreementDlg.wxs" />
<Compile Include="Content\GlobalSetupFolderDlg.wxs" />
<Compile Include="Content\GlobalWelcomeDlg.wxs" />
<Compile Include="Content\GlobalWixUI.wxs" />
<Compile Include="Content\Product.wxs" />
<Compile Include="Content\UserFiles.wxs" />
<Compile Include="Content\UserIIS.wxs" />
<Compile Include="Content\UserRegistry.wxs" />
</ItemGroup>
<ItemGroup>
<Folder Include="conf\" />
<Folder Include="Content\" />
<Folder Include="Images\" />
<Folder Include="lib\" />
</ItemGroup>
<ItemGroup>
<Content Include="AppPoolAttrs.xml" />
<Content Include="AppPoolUpgradeChanges.xml" />
<Content Include="conf\default.yml" />
<Content Include="Content\CustomActions.CA.dll" />
<Content Include="Content\GlobalProperties.wxi" />
<Content Include="Content\License.en-us.rtf" />
<Content Include="CustomWix.targets" />
<Content Include="Images\Banner.bmp" />
<Content Include="Images\DEST.ICO" />
<Content Include="Images\dialog.bmp" />
<Content Include="Images\dialog_cust.bmp" />
<Content Include="Images\dialog_template.bmp" />
<Content Include="Images\Exclam.ico" />
<Content Include="Images\folder.ico" />
<Content Include="Images\folderNew.ico" />
<Content Include="Images\New.ico" />
<Content Include="Images\warn.ico" />
<Content Include="lib\WixIIsExtension.dll" />
<Content Include="lib\WixMsmqExtension.dll" />
<Content Include="lib\WixUIExtension.dll" />
<Content Include="lib\WixUtilExtension.dll" />
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Content\en-us.wxl" />
</ItemGroup>
<Import Project="CustomWiX.Targets"
Condition="Exists('CustomWiX.targets')" />
<Import Project="$(WixTargetsPath)" Condition=" '$(WixTargetsPath)'
!= '' " />
<Import
Project="$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets"
Condition=" '$(WixTargetsPath)' == '' AND
Exists('$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets')
" />
<Target Name="EnsureWixToolsetInstalled" Condition="
'$(WixTargetsImported)' != 'true' ">
<Error Text="The WiX Toolset v3.11 (or newer) build tools must be
installed to build this project. To download the WiX Toolset, see
http://wixtoolset.org/releases/" />
</Target>
</Project>
I tried passing $(FilePath), $(PVersion) and $(BldNum) from project
properties, but no luck. I cannot hard code these values in .targets
or .wixproj file, since they have to be run from both Visual Studio
and MSBuild. Also, I am not able to pass OutputName and OutputPath
from Visual Studio.
The main issue is that when you set the variables in Project Properties UI, the values can only pass to the variables in the xxx.wixproj rather than CustomWiX.Targets file.
And this approach is local (modify only the properties of the xxx.wixproj file, which still be overridden by the custom target values).
In more detail, when it reloads the xxxx.wixproj which contains the custom target file, MSBuild will load the xml nodes line by line, since MSBuild properties support forward override values. Simply said, if the same value is defined later, the previous value is overwritten. And the same properties are defined in the custom target file which is imported under the those properties, so the properties in the custom targets file will always override the properties.
Besides, when you pass some variables in the project Properties UI, the values will overwrite the values in the xxx.wixprojrather than custom targets file. And then when you build again, the values in custom targets will still override the values you modified in project properties, so it won't work.
Differ from VS IDE, the msbuild command line can override the value with -p: XXX (property name)= XXXXXX, which is global, so this problem does not occur.
Suggestion
1) If you still want to modify those properties by overriding the value of the project properties, remove the same properties from the custom targets file and move them to wixproj so that they can be used directly.
2) Since the custom target file always overwrites the same properties, you can modify the specific properties directly in the custom target file without having to modify the wixproj file directly.
Update1
The wixvariables(Properties-->Build-->Define Variables) does not work in the xxxx.wixproj file but only for wix file like Product.wxsfile. If you define the property $(Filepath) in the Define Variables, it will never be used for MSBuild. So there is no way to set the properties in Property UI for msbuild Properties.
Besides, $ is used to call a property of MSBuild and MSBuild define a property only under PropertyGroup of xxx.xxxproj like <PropertyGroup><FilePath> xxx</FilePath><\PropertyGroup>.
Solution
You can customize your build by using Directory.Build.targets and remember keeping the name as the document said which is designed by that with the effect. Then you should put this file under the solution folder so that it can work for all the projects.xxx.props file will import on the top of the xxxx.xxproj, so it can not override the values and only the Directory.Build.targets which is imported at the bottom of the xx.xxproj file does.
Then you can define the variables in the file like:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<FilePath>xxxxx</FilePath>
</ProperGroup>
.........
</Project>
Hope it could help you.
I'm attempting to create a nupkg with Visual Studio using the built in nuget package building and include the build directory from my project in the nupkg. It seems like it should be a fairly simple task but I can't get it to work. From my googling adding either of these to my csproj file should work, but both create an empty 'build' directory in the nupkg:
<ItemGroup>
<None Include="build\**">
<Pack>true</Pack>
<PackagePath>build\</PackagePath>
<IncludeInPackage>true</IncludeInPackage>
</None>
</ItemGroup>
Using nuget pack to create the package with the following in my nuspec does work:
<files>
<!-- Include everything in \build -->
<file src="build\**" target="build" />
</files>
Include build directory in nuget package using visual studio pack
According to the document Including content in a package, you should use the properties <Pack>true</Pack> and <PackagePath>build\</PackagePath>:
If you want to copy all your content to only a specific root folder(s) (instead of content and contentFiles both), you can use the MSBuild property ContentTargetFolders, which defaults to "content;contentFiles" but can be set to any other folder names.
PackagePath can be a semicolon-delimited set of target paths.
Specifying an empty package path would add the file to the root of the
package.
So, you can change your ItemGroup like following:
<ItemGroup>
<None Include="build\**" Pack="True" PackagePath="build\" />
</ItemGroup>
Update:
I believe this is the same as what I added but in a different XML
structure and without the Pack attribute
The Pack attribute is the key point. It works fine with your XML structure and the Pack attribute. You should make sure you have the files in the build folder in your project folder:
Check my test demo below:
Update2:
Ah! You are using the .net framework project!! That the reason for this issue. This method is used for .net standard and .net core project by default and it not work for .net framework. To resolve this issue you have to use the .nupsec file, like you post in the question.
If you still want to include build directory in nuget package using visual studio pack, you need change your project type to SDK type:
Check this document for some more details.
Then you can use the method, which we talked about before.
Hope this helps.
The solution to this issue was to upgrade the project to SDK type (Xamarin binding projects by default use the old format but seem to work with the new type) and then use:
<ItemGroup>
<None Update="build\**">
<IncludeInPackage>true</IncludeInPackage>
</None>
</ItemGroup>
To include the build directory. The alternative is using nuget pack.
When converting the project make sure to leave in the Xamarin import:
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.ObjCBinding.CSharp.targets" />
Here's how my project file looks afterwards:
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<PackageId></PackageId>
<PackageVersion>3.3.2</PackageVersion>
<ReleaseVersion>$(PackageVersion)</ReleaseVersion>
<AssemblyVersion>$(PackageVersion)</AssemblyVersion>
<Authors>Nick Brook</Authors>
<Description></Description>
<Copyright></Copyright>
<PackageProjectUrl></PackageProjectUrl>
<Summary></Summary>
<PackageTags></PackageTags>
<Title></Title>
<PackageReleaseNotes>Initial Release</PackageReleaseNotes>
<OutputType>Library</OutputType>
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
<OutputPath>bin\$(Configuration)</OutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<PackageOutputPath>packed</PackageOutputPath>
<PackOnBuild>true</PackOnBuild>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<ObjcBindingApiDefinition Include="ApiDefinition.cs" />
</ItemGroup>
<ItemGroup>
<ObjcBindingCoreSource Include="Structs.cs" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Structs.cs" Condition=" '$(EnableDefaultCompileItems)' == 'true' " />
<Compile Remove="ApiDefinition.cs" Condition=" '$(EnableDefaultCompileItems)' == 'true' " />
</ItemGroup>
<ItemGroup>
<None Remove="packed\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Build.Download" Version="0.4.11" />
<PackageReference Include="NuGet.Build.Packaging" Version="0.2.2" />
</ItemGroup>
<ItemGroup>
<None Update="build\**">
<IncludeInPackage>true</IncludeInPackage>
</None>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.ObjCBinding.CSharp.targets" />
</Project>
I'm trying to use WebDeploy to publish a website using custom MSDeploy skip rules and a publish profile saved in Visual Studio 2012.
I have the publish profile working from the command line, but the skip rule to skip deleting a folder isn't working.
I have an ErrorLog subfolder in my web app with a web.config file inside it to set the proper folder permissions. Without any skip rules, the ErrorLog folder and web.config file are published normally, but all existing error log files in the folder on the server are deleted on publish.
Error with <SkipAction>Delete</SkipAction>
When I add a custom skip rule to my wpp.targets file, the skip rule is no longer accepting a value for the <SkipAction> element. If I set <SkipAction>Delete</SkipAction>, I get the following error:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets(4377,5): error : Web deployment task failed. (Unrecognized skip directive 'skipaction'. Must be one of the following: "objectName," "keyAttribute," "absolutePath," "xPath," "attributes.<name>.") [C:\inetpub\wwwroot\My.Website\My.Website\My.Website.csproj]
If I simply omit the <SkipAction> element, the ErrorLog folder is deleted when it would normally be published.
If I set <SkipAction></SkipAction>, again, the ErrorLog folder is deleted on publish.
If I set <KeyAttribute>Delete</KeyAttribute>, then ErrorLog and the web.config file are published normally.
My understanding is that in order to use custom skip rules, you need to call MSBuild from the command line instead of publishing from within VS 2012. I'd still like to use my saved publishing profiles, however, and I understand that's now possible as of VS 2012.
My MSBuild command line:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe My.Website.sln /p:Configuration=Release;DeployOnBuild=true;PublishProfile="Test Server - Web Deploy"
My.Website.wpp.targets:
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AfterAddIisSettingAndFileContentsToSourceManifest>AddCustomSkipRules</AfterAddIisSettingAndFileContentsToSourceManifest>
</PropertyGroup>
<Target Name="AddCustomSkipRules">
<Message Text="Adding Custom Skip Rules" />
<ItemGroup>
<MsDeploySkipRules Include="SkipErrorLogFolder1">
<SkipAction></SkipAction>
<KeyAttribute>Delete</KeyAttribute>
<ObjectName>dirPath</ObjectName>
<AbsolutePath>$(_Escaped_WPPAllFilesInSingleFolder)\\ErrorLog$</AbsolutePath>
<XPath></XPath>
</MsDeploySkipRules>
</ItemGroup>
</Target>
</Project>
My MSBuild output showing the custom skip rule, but still deleting the files:
GenerateMsdeployManifestFiles:
Generate source manifest file for Web Deploy package/publish ...
AddCustomSkipRules:
Adding Custom Skip Rules
MSDeployPublish:
Start Web Deploy Publish the Application/package to http://testserver.domain.com/MSDEPLOYAGENTSERVICE ...
Starting Web deployment task from source: manifest(C:\inetpub\wwwroot\My.Website\My.Website\obj\Release\Package\My.Website.SourceManifest.xml) to Destination: auto().
Deleting filePath (MyWeb/ErrorLog\test.txt).
Updating setAcl (MyWeb/).
Updating setAcl (MyWeb/).
Updating filePath (MyWeb/ErrorLog\Web.config).
Updating filePath (MyWeb/Web.config).
Updating setAcl (MyWeb/).
Updating setAcl (MyWeb/).
Successfully executed Web deployment task.
Publish is successfully deployed.
Edit: It turns out you are right: the skip directive is ignored when executed from Visual Studio.
Fortunately, there's a workaround.
What you want is this:
<!-- Skip the deletion of any file within the ErrorLog directory -->
<MsDeploySkipRules Include="SkipErrorLogFolder1">
<SkipAction>Delete</SkipAction>
<ObjectName>filePath</ObjectName>
<AbsolutePath>ErrorLog</AbsolutePath>
</MsDeploySkipRules>
In addition, you need to prevent VS from using the UI-task (which appears to contain a bug regarding the skip rules). You can do this by declaring the following in your wpp.targets or pubxml:
<PropertyGroup>
<UseMsDeployExe>true</UseMsDeployExe>
</PropertyGroup>
I've tested this locally and I can confirm that it works as desired: the additional file is updated but no files in the directory are deleted.
For reference, here is my complete .wpp.targets file with working skip rule to skip deleting the ErrorLog folder and custom ACLs to make the ErrorLog folder writable on the server.
As of VS 2012 Update 3, this only works when publishing with MSBuild from the command line with the DeployOnBuild=true;PublishProfile="Test Server - Web Deploy" options passed to MSBuild. This will not work when publishing from within VS.
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<UseMsdeployExe>true</UseMsdeployExe> <!-- Required for the MSDeploySkipRules to work -->
<DeployManagedPipelineMode>Integrated</DeployManagedPipelineMode>
</PropertyGroup>
<PropertyGroup>
<AfterAddIisSettingAndFileContentsToSourceManifest>
$(AfterAddIisSettingAndFileContentsToSourceManifest);
AddCustomSkipRules;
</AfterAddIisSettingAndFileContentsToSourceManifest>
</PropertyGroup>
<Target Name="AddCustomSkipRules">
<Message Text="Adding Custom Skip Rules" />
<ItemGroup>
<MsDeploySkipRules Include="SkipErrorLogFolder">
<SkipAction>Delete</SkipAction>
<ObjectName>filePath</ObjectName>
<AbsolutePath>ErrorLog</AbsolutePath>
<XPath></XPath>
</MsDeploySkipRules>
</ItemGroup>
</Target>
<PropertyGroup>
<AfterAddIisSettingAndFileContentsToSourceManifest>
$(AfterAddIisSettingAndFileContentsToSourceManifest);
SetCustomACLs;
</AfterAddIisSettingAndFileContentsToSourceManifest>
<AfterAddDeclareParametersItemsForContentPath>
$(AfterAddDeclareParametersItemsForContentPath);
SetCustomAclParameters;
</AfterAddDeclareParametersItemsForContentPath>
</PropertyGroup>
<Target Name="SetCustomACLs">
<Message Text="Setting Custom ACLs" />
<ItemGroup>
<!--Make sure the application pool identity has write permission to the download folder-->
<MsDeploySourceManifest Include="setAcl"
Condition="$(IncludeSetAclProviderOnDestination) And Exists('$(_MSDeployDirPath_FullPath)\ErrorLog')">
<Path>$(_MSDeployDirPath_FullPath)\ErrorLog</Path>
<setAclAccess>Write</setAclAccess>
<setAclResourceType>Directory</setAclResourceType>
<AdditionalProviderSettings>setAclResourceType;setAclAccess</AdditionalProviderSettings>
</MsDeploySourceManifest>
</ItemGroup>
</Target>
<Target Name="SetCustomAclParameters">
<Message Text="Setting Custom ACL Parameters" />
<EscapeTextForRegularExpressions Text="$(_MSDeployDirPath_FullPath)">
<Output TaskParameter="Result" PropertyName="_EscapeRegEx_MSDeployDirPath" />
</EscapeTextForRegularExpressions>
<ItemGroup>
<MsDeployDeclareParameters Include="Add write permission to ErrorLog folder"
Condition="$(IncludeSetAclProviderOnDestination) and Exists('$(_MSDeployDirPath_FullPath)\ErrorLog')">
<Kind>ProviderPath</Kind>
<Scope>setAcl</Scope>
<Match>^$(_EscapeRegEx_MSDeployDirPath)\\ErrorLog$</Match>
<Description>Add write permission to ErrorLog folder</Description>
<DefaultValue>Default Web Site/ErrorLog</DefaultValue>
<Value>$(DeployIisAppPath)/ErrorLog</Value>
<Tags>Hidden</Tags>
<Priority>$(VsSetAclPriority)</Priority>
<ExcludeFromSetParameter>True</ExcludeFromSetParameter>
</MsDeployDeclareParameters>
</ItemGroup>
</Target>
</Project>
Another approach is to avoid the SkipAction tag, I've successfully used this setup directly from VS 2013:
<Target Name="AddCustomSkipRules"
AfterTargets="AddIisSettingAndFileContentsToSourceManifest">
<Message Text="Adding Custom Skip Rules" />
<ItemGroup>
<MsDeploySkipRules Include="SkipMedia">
<objectName>dirPath</objectName>
<absolutePath>media</absolutePath>
</MsDeploySkipRules>
<MsDeploySkipRules Include="SkipUpload">
<objectName>dirPath</objectName>
<absolutePath>upload</absolutePath>
</MsDeploySkipRules>
</ItemGroup>
</Target>
Only caveat as far as I can tell is that, it will ignore both update, delete and add operations.
After many hours looking through the net. i created this file as {myprojectname}.wpp.targets under the site root folder. it works when publishing with visual studio. the media folder is ignored. i am using VS 2010.
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<UseMsdeployExe>true</UseMsdeployExe>
<!-- Required for the MSDeploySkipRules to work -->
<DeployManagedPipelineMode>Integrated</DeployManagedPipelineMode>
</PropertyGroup>
<PropertyGroup>
<AfterAddIisSettingAndFileContentsToSourceManifest>
$(AfterAddIisSettingAndFileContentsToSourceManifest);
AddCustomSkipRules;
</AfterAddIisSettingAndFileContentsToSourceManifest>
</PropertyGroup>
<Target Name="AddCustomSkipRules">
<Message Text="Adding Custom Skip Rules - WPP Targets 2" />
<ItemGroup>
<MsDeploySkipRules Include="SkipErrorLogFolder">
<SkipAction>Delete</SkipAction>
<ObjectName>dirPath</ObjectName>
<AbsolutePath>media</AbsolutePath>
<XPath></XPath>
<Apply>Destination</Apply>
</MsDeploySkipRules>
</ItemGroup>
</Target>
</Project>
I think the problem is in incorrect AbsolutePath. It should be a regular expression to match file or folder. so it should be properly escaped. Below is the sample which worked for me (I wanted to skip removal of app_offline.htm to make delivery part of larger deployment)
<PropertyGroup>
<PackageUsingManifestDependsOn>$(PackageUsingManifestDependsOn);AddCustomSkipRules</PackageUsingManifestDependsOn>
</PropertyGroup>
<Target Name="AddCustomSkipRules">
<ItemGroup>
<MsDeploySkipRules Include="SkipAppOfflineOnDeploy">
<SkipAction></SkipAction>
<ObjectName>filePath</ObjectName>
<AbsolutePath>app_offline\.htm</AbsolutePath>
<Apply>Destination</Apply>
<XPath></XPath>
</MsDeploySkipRules>
</ItemGroup>
</Target>
Works for me: My Full prepprod.pubxml file in my App_Data/PublishProfiles folder in my web solution. Web Deploy no longer deletes files out of the cachefiles folder on webdeploy from VS 2015. The first PropertyGroup was auto-generated by using the web publishing gui in Visual Studio. I added the second PropertyGroup, and the Target section from previous comments.
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Production</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>{masked}</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<MSDeployServiceURL>{masked}</MSDeployServiceURL>
<DeployIisAppPath>{masked}</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<MSDeployUseChecksum>true</MSDeployUseChecksum>
<EnableMSDeployBackup>True</EnableMSDeployBackup>
<UserName>{masked}</UserName>
<_SavePWD>True</_SavePWD>
<PublishDatabaseSettings>
<Objects xmlns="">
</Objects>
</PublishDatabaseSettings>
<ExcludeFilesFromDeployment>packages.config;*.bat;*.sln;*.suo,*.p4ignore</ExcludeFilesFromDeployment>
<ExcludeFoldersFromDeployment>packages;cachefiles;.ebextensions</ExcludeFoldersFromDeployment>
</PropertyGroup>
<PropertyGroup>
<AfterAddIisSettingAndFileContentsToSourceManifest>
$(AfterAddIisSettingAndFileContentsToSourceManifest);
AddCustomSkipRules;
</AfterAddIisSettingAndFileContentsToSourceManifest>
</PropertyGroup>
<Target Name="AddCustomSkipRules">
<Message Text="Adding Custom Skip Rules" />
<ItemGroup>
<MsDeploySkipRules Include="SkipcachefilesFolder">
<objectName>dirPath</objectName>
<absolutePath>cachefiles</absolutePath>
</MsDeploySkipRules>
</ItemGroup>
</Target>
</Project>
This worked for me in vs 2015, website project type:
<!--Added inside existing <ProjectGroup> tag-->
<AfterAddIisSettingAndFileContentsToSourceManifest>AddCustomSkipRules</AfterAddIisSettingAndFileContentsToSourceManifest>
<!--Added new ProjectGroup tag inside <Project></Project>-->
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
</PropertyGroup>
<!--Added inside existing <Project> tag at the bottom-->
<Target Name="AddCustomSkipRules">
<Message Text="Adding Custom Skip Rules" />
<ItemGroup>
<MsDeploySkipRules Include="SkipConfigFolder">
<SkipAction></SkipAction>
<!--<KeyAttribute>Delete</KeyAttribute>-->
<ObjectName>dirPath</ObjectName>
<AbsolutePath>App_Data\\Composite\\Logfiles</AbsolutePath>
<XPath>
</XPath>
</MsDeploySkipRules>
</ItemGroup>
</Target>
I am working with Visual Studio 2010. I have directed project output to a specific folder which will contain all the DLLs and EXEs when built. However when I clean the solution, the folder is not getting cleaned, and the DLLs are still present in it.
Can anyone tell me how to handle the clean solution command to clear out the folders I want to clean? I tried working with MSBuild and handling the BeforeClean and AfterClean targets, but it did not provide the desired result.
The answer from Sergio should work but I think it could be cleaner to override the BeforeClean/AfterClean targets. These are hooks into the build/clean process provided by microsoft. When you do a clean, VS do call the targets : BeforeClean;Clean;AfterClean and by default the first and the last do nothing.
In one of your existing .csproj file you can add the following :
<Target Name="BeforeClean">
<!-- DO YOUR STUFF HERE -->
</Target>
You can add to your VS .sln file special target named let's say BuildCustomAction.csproj:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
</PropertyGroup>
<ItemGroup>
<CleanOutCatalogFiles Include="..\..\bin\$(Configuration)\**\*.dll">
<Visible>false</Visible>
</CleanOutCatalogFiles>
<CleanOutCatalogFiles Include="..\..\bin\$(Configuration)\**\*.exe">
<Visible>false</Visible>
</CleanOutCatalogFiles>
</ItemGroup>
<Target Name="Build">
</Target>
<Target Name="Rebuild"
DependsOnTargets="Clean;Build">
</Target>
<Target Name="Clean"
Condition="'#(CleanOutCatalogFiles)'!=''">
<Message Text="Cleaning Output Dlls and EXEs" Importance="high" />
<Delete Files="#(CleanOutCatalogFiles)" />
</Target>
</Project>
Place it everywhere you want and specify relative path to the output catalog for your binaries. Add in VS this project as existing. That's all. With this you can do own custom actions for three common actions in VS: Build, Rebuild, Clean.
There exists more complex way to customize build process using CustomBeforeMicrosoftCommonTargets and CustomAfterMicrosoftCommonTargets but it requires to be very good in MSBuild.
Hope this helps.