Visual Studio 2010: How to exclude folder/files from "Build Deployment Package"? - visual-studio-2010

Is it possible to exclude specific files or folders from "Build Deployment Package" function in VS 2010?
In VS 2008 it was possible with Web Deployment package, unfortunately this project is not available in VS2010.

I need to exclude some files also, I want to remove assemblies .xml files from the deploy (I don't need them on the server), I couldn't find anything on the web so I decide to look for it on my own.
After digging into the msbuild of the MsPublish I found it, you need to setup the following in your project (edit manualy the .csproj):
<ItemGroup>
<!-- This will exclude the .xml files from the bin folder -->
<ExcludeFromPackageFiles Include="$(OutputPath)*.xml" />
<!-- This will exclude the tmp folder from the bin folder -->
<ExcludeFromPackageFolders Include="$(OutputPath)tmp" />
</ItemGroup>

just to clarify the ItemGroup include should be after
after the following import in your .csproj:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
eg.
<ItemGroup>
<ExcludeFromPackageFiles Include="Sample.Debug.xml">
<FromTarget>Project</FromTarget>
</ExcludeFromPackageFiles>
</ItemGroup>
Sayed Ibrahim Hashimi has a good post on this: http://sedodream.com/2010/05/01/WebDeploymentToolMSDeployBuildPackageIncludingExtraFilesOrExcludingSpecificFiles.aspx

Related

Change LibSassBuilder output directory

I'm using LibSassBuilder in a Blazor project. I have read the docs and it's unclear to me if the package's config allows you to specify an output directory. I'd prefer to keep my .scss files outside of wwwroot and just place the compiled .css files there-- but I don't see if there's a way to do this. If not, is there a way to specify a file move to wwwroot in the Visual Studio build pipeline?
I'm also developing a Blazor project using LibSassBuilder. This is how I got it to work in my .csproj file:
<PropertyGroup>
<LibSassOutputStyle>compressed</LibSassOutputStyle>
<LibSassOutputStyle Condition="'$(Configuration)' == 'Debug'">expanded</LibSassOutputStyle>
</PropertyGroup>
<ItemGroup>
<CSSFiles Include="**/*.css" />
</ItemGroup>
<Target Name="MoveCSS" AfterTargets="Build">
<Move SourceFiles="#(CSSFiles)" DestinationFolder="wwwroot/css" />
</Target>

Restore nuget package in different folder

We have some projects (Plugins) which use in several projects, the output of these projects will copy to the specific folder in the target projects (Plugins folder).
We pack project with Visual studio 2019 Pack option and after that, we push npkg files to our local NuGet server for further use.
The problem is when we want to get these packages, Package Manager should put lib files in the Plugins folder, but unfortunately, the package manager extracts these in the root folder (bin).
My question is: How can I config nuspec file to force package manager to extract to the right folder, and can I do it with visual studio or I have to create nuspec file manually.
You should use a <packages_id>.props file to realize it.
create a file called <packages_id>.props under the build folder of your lib project.
You should note that if your nupkg file is called Plugins.1.0.0.nupkg, you should name this file as Plugins.props so that it will work.
add these on Plugins.props file:
<Project>
<Target Name="CopyFiles" BeforeTargets="Build">
<ItemGroup>
<File Include="$(MSBuildThisFileDirectory)..\Plugins\*.*"></File>
</ItemGroup>
<!--It will copy the plugins output files into the Plugins folder of the goal project-->
<Copy SourceFiles="#(File)" DestinationFolder="$(ProjectDir)Plugins"></Copy>
</Target>
</Project>
add these on Plugins.csproj file:
<ItemGroup>
<None Include="bin\Debug\netstandard2.0\Plugins.dll" Pack="true" PackagePath="Plugins"></None>
//add any output files from Plugins project which you want them to be packed
<None Include="build\Plugins.props" Pack="true" PackagePath="build"></None>
</ItemGroup>
use Pack Button to create the new release version of your nuget pakckage.
Also, when you install this new version of nuget package, please clean your nuget caches or delete all files under C:\Users\xxx(current user)\.nuget\packages.
When you finish the installing process, please click Build button and the files will generated under Plugins folder.
There is also a similar issue about this.

Visual Studio Publish - Include folder that is not added to Project

Using - VS2013, VS2015, .Net 4.5
I have several Asp.Net projects each of which has an images/books folder that contains 1000's of images. I don't include these folders in the project ( the .csproj file) files so they are always left out when using using Publish.
I want to include these folders when publishing to UAT and LIVE without having to add them to my project as having so many images in your project is problematic.
What do I need to do to make this happen?
You can use this hook in your project file to add files or folder to deploy :
<!--Hook to deploy add files -->
<PropertyGroup>
<CollectFilesFromContentDependsOn>
AddFilesToDeploy;
$(CollectFilesFromContentDependsOn);
</CollectFilesFromContentDependsOn>
</PropertyGroup>
<!--Add files to deploy -->
<Target Name="AddFilesToDeploy">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="CurrentAssembly" />
</GetAssemblyIdentity>
<ItemGroup>
<JsFile Include="App\MyApp.min-%(CurrentAssembly.Version).js" />
<FilesForPackagingFromProject Include="%(JsFile.Identity)">
<DestinationRelativePath>App\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
Warning : this hook work when you publish a web application from visual studio. This doesn't work with the publish task with Team Foundation Server because it's not the task CollectFilesFromContent that is called

Copying files into the source code before building a deploy package with MsBuild on TFS

I'm using TFS as a build server to use MsBuild for building and packaging a solution into a web deploy-package.
MSBuild Arguments: /p:CreatePackageOnPublish=true /p:DeployOnBuild=true /p:DeployTarget=Package
Now I want to copy a couple of files into the source-files before building the package, so they will end up in the App_Data-directory when deployed to IIS. I was thinking of doing it as part of the TFS-build, and have created an InvokeProcess-action which calls xcopy and copies the files into the SourcesDirectory, however they don't appear in the built zip-package.
Into what directory should I copy the files, and where in the build-process?
Are there a better way to do this? I was thinking of a Post Build-event in the project-file, however I only want this to be run by specific TFS-build, and not for all builds.
I deploy specific js versionned files with this hook in my project file :
<!--Hook to deploy add files -->
<PropertyGroup>
<CollectFilesFromContentDependsOn>
AddFilesToDeploy;
$(CollectFilesFromContentDependsOn);
</CollectFilesFromContentDependsOn>
</PropertyGroup>
<!--Add files to deploy -->
<Target Name="AddFilesToDeploy">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="CurrentAssembly" />
</GetAssemblyIdentity>
<ItemGroup>
<JsFile Include="script\myApp.min-%(CurrentAssembly.Version).js" />
<FilesForPackagingFromProject Include="%(JsFile.Identity)">
<DestinationRelativePath>%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
If i remember, this doesn't work for a tfs build because CollectFilesFromContent is not executed in this process, so i have copied the files in a post build event:
if not '$(TeamFoundationServerUrl)' == '' (
xcopy "$(ProjectDir)script\myApp.min-#(VersionNumber).js" "$(OutDir)_PublishedWebsites\$(MSBuildProjectName)\script"
)

Ignore file from delete during WebDeploy

I'm using TeamCity to build and deploy a collection of MVC Applications via msbuild and WebDeploy.
In a step previous to my solution build/deploy, I copy an app_offline.htm to the deploy directory so that I can perform SQL updates and other web/solution management steps including the build.
One of the setting in the WebDeploy is to delete files that aren't included in the project, or not needed to run the site. This deletes my app_offline.htm file each time. While I understand this is kind of the desired result, is there a way to exclude this file from being deleted from the deployment directory upon the deploy?
I've tried adding an ItemGroup with the ExcludeFromPackageFiles option, with no results.
I had a similar problem, wanting to keep minified javascript files in the deployment package even though they're not part of the project.
I added a custom MSBuild target for this, that works for me:
<!-- ====== Package the minify files ===== -->
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles1;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<PropertyGroup>
<AfterAddIisSettingAndFileContentsToSourceManifest>
MakeEmptyFolders
</AfterAddIisSettingAndFileContentsToSourceManifest>
</PropertyGroup>
<Target Name="CustomCollectFiles1">
<ItemGroup>
<!-- =====Controls\Javascript folder ==== -->
<_CustomFilesForRootFolder Include=".\Controls\Javascript\*.min.js">
<DestinationRelativePath>%(RecursiveDir)%(Filename)%(Extension) </DestinationRelativePath>
</_CustomFilesForRootFolder>
<FilesForPackagingFromProject Include="%(_CustomFilesForRootFolder.Identity)">
<DestinationRelativePath>.\Controls\Javascript\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
This other question " Custom app_offline.htm file during publish " suggests one possible way for the final result you describe:
I use my own
app_offline.htm_
file in the solution, which gets
published. My deployment script then
renames it (removing the trailing _)
to make it active.
I can then run my db scripts/do
whatever then rename the file bringing
the site back.

Resources