TFS 2015 Build files and Publish websites - asp.net

I recently started working with TFS 2015 (Update 4). And I'm trying to configure and build to do the folowing:
Restore nuget packets
Build whole solution
Publish (move to specific uri)
My solution has the folowing structure:
Solution
DALs (EF6 code first model)
WPF App 1
ASP.NET Website 1
WPF App 2
ASP.NET Website 2
Note: Both Websites have publish profiles named "Publish", and both are same except the publishUrl inside of them.
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<PublishProvider>FileSystem</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>..\Deploy\AppServerHost</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
</PropertyGroup>
What have I tried on TFS...
And the publish:
What I'm trying to acomplish, is that when I start the build, it should build the whole solution, copy the release of WPF regulary, and most important, not just build the websites, it should also publish them. Because now I only get their bins.

To build the whole solution, you need to make sure you have mapped all your projects/the whole solution folder in Repository tab, and specify the solution or use **\*.sln (you have already done this according to your screenshot) in Visual Studio Build task:
You only get bins because you only specify **\binin Contents of Copy and Publish Build Artifacts task. Since you are using TFS 2015.4, we recommend that you do not use Copy and Publish Build Artifacts task, it's deprecated. Instead, you should use the Copy Files and Publish Build Artifacts tasks.
In Copy Files task, specify match pattern filters (one on each line) that you want to apply to the list of files to be copied.
In Publish Build Artifacts task, specify the path to the folder or file you want to publish. You could refer to the links for more details.

Related

Install a nuget package to a folder without a csproj

Assuming I have packaged a .net application e.g. MyConsoleApp.nupkg and have it available in a source, how would I go about "installing" this to a folder, such that I can run it from this folder:
my-folder/MyConsoleApp.dll
my-folder/Newtonsoft.Json.dll
....Other references....
I have tried nuget install with packagesDirectory option, but this gives the familiar output in the packages folder e.g:
myconsoleapp/1.0.0/lib/netcoreapp3.1/MyConsoleApp.dll
newtonsoft.json/11.0.1/lib/netstandard2.0/Newtonsoft.Json.dll
newtonsoft.json/11.0.1/lib/netstandard1.3/Newtonsoft.Json.dll
newtonsoft.json/11.0.1/lib/net20/Newtonsoft.Json.dll
....Other references....
I imagine there is a msbuild target which copies the correct content out of the packages directory to a build directory - is there an easy way to use this?
I have tried using dotnet restore/build with variations of a .proj file using PackageReference which make no reference to a specific build target, but these have not worked:
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="MyConsoleApp" Version="*" />
</ItemGroup>
<Project>
I don't want to make a MyDummy.csproj which references my console app (or asp.net core app) to achieve this because it doesn't seem very clean, and I'm worried about getting the SDK and <PropertyGroup> stuff compatibly correct.
I understand this may not fall under best practices, but I would like to see if it can be done in any case.
Background
I want to deploy a mesh of c# core libraries, applications and plugins such that they all use the exact same versions.
The libraries (core application framework) are referenced by the applications (web apis, background service workers) and by the plugins (dotnet-script with nuget references to the libraries). The plugins are in turn invoked by the libraries.
The plugins must reference the same library assemblies as loaded by the applications, yet are resolved as NuGet references at runtime, which avoids a long list of guessed references to System.Etc.Dll in the scripts and related runtime failures.
Installing the applications via nuget packages leads to an interesting way to get a single source of truth for all - the nuget source.
I've seen how dotnet-script manages to do it:
https://github.com/filipw/dotnet-script/blob/master/src/Dotnet.Script.DependencyModel/ProjectSystem/csproj.template
During the msbuild of a project that has packagereferences, you are able to get access to the list of references. This is similar to doing a full build of a dummy project, but looks likely the only way to do this as of now - nobody seems to want to answer so I'll leave this here!

DeployOnBuild not taking effect when building web app in Visual Studio 2017

I have a web application in VS 2017 for which I've defined a publish profile which works, happily, deploying / publishing the website to a location on the file system.
I understood that this was possible as part of the regular build process, i.e. just building the solution in Visual Studio or TFS build - and that this was achievable with a section like this:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DeployOnBuild>True</DeployOnBuild>
<PublishProfile>ProfileName</PublishProfile>
</PropertyGroup>
However, this has no effect whatsoever, the build output log just shows the regular build happening and no attempt to publish.
Should this work as suggested in various answers on here and MSDN - and if so, what is wrong with the above?
(In case anybody is wondering, the reason for doing this is that a single solution being built by TFS cannot separately publish > 1 web application with separate publish profiles as required with the build definition MSBuildArguments setting).
I want to credit #Andy-MSFT who posted a very close answer, but in the end there were some vital details missing and some corrections required to make it work.
First off, the working solution was:
<Target Name="Deploy" AfterTargets="Build">
<MSBuild
Condition="'$(DeployOnBuild)'!='true' And '$(Configuration)|$(Platform)' == 'Release|AnyCPU'"
Projects="$(ProjectPath)"
Targets="WebPublish"
Properties="DeployOnBuild=true;PublishProfile=FolderProfile"/>
</Target>
The WebPublish target will only work on a TFS build server if the "Web Developer Tools" of Visual Studio (2017 in my case, as per the question) are installed. Note that the "Projects" attribute had to be set with $(ProjectPath) which is also different to Andy's answer and was also needed for this to work.
The DeployOnBuild property specifically was ignored when set statically in the project file. Apparently it is a special property that must be set globally on the commandline.
As a workaround, you could call MSBuild again to pass the property. See How to: Extend the Visual Studio Build Process
Open the .csproj file with text editor.
Add below snippet at the end, then save it.
<Target Name="AfterBuild">
<MSBuild Condition="'$(DeployOnBuild)'!='true'" Projects="$(MSBuildProjectFullPath)" Properties="DeployOnBuild=true;PublishProfile=YourPublishProfile;BuildingInsideVisualStudio=False"/>
</Target>
Below threads for your reference:
Publish WebDeploy Automatically with VS Build
Visual Studio 2013 Build and Publish

Precompiling and Deploying website from Visual Studio Team Services

We're using Visual Studio Team Services with Git as the source control system and I've configured a build which executes successfully online. Ideally I'd like to:
After building the site in VSO, precompile and dump the aspx and .dll files to the git repository
On the on-premises web server, pull from git and move to our staging site
The second part I can figure out on my own, but the documentation for VSTeam seems sketchy on how to dump the compiled sources to git. I've kept the default build configration almost the same as the default with the exception of a Powershell script which is supposed to create artifacts for the drop. Despite this, the drop.zip file create is empty.
The following is how my build definition is set up in VSO.
Instead of the PowerShell script, you'd be able to use the "Copy and Publish artefacts" and have it create a specific artefact with the specific bits you need:
This will automatically create a named build artefact which you can then use from Release Management as an input.
The PowerShell script was used in the XAML builds when used with the "Project Output | As Configured" option.
To create your "packaged" website, you need to add a couple of parameters to the MsBuild/Visual Studio Build step to instrict the compiler to package your website:
/p:DeployOnBuild=true /p:DeployTarget=Package
/p:SkipInvalidConfigurations=true /p:PackageAsSingleFile=false
/p:AspNetCompileMerge=true
Optionally you can configure your target directory as well using
/p:PackageLocation="$(Build.BinariesDirectory)\Published"
If you do this, you need to configure this directory as your copy root in the copy and publish task.
I did a quick look at the Power-Shell script, there are two issues with it:
It still use the variables like "$Env:TF_BUILD_SOURCESDIRECTORY" which does not exist in VSTS(VSO). See Variables for VSTS.
It copies the files from "BUILD_SOURCESDIRECTORY" folder to "BUILD_BINARIESDIRECTORY". But the "Publish Build Artifacts" step in your definition publish the files in "BUILD_ARTIFACTSTAGINGDIRECTORY" folder.
So if you want to use this script, you need to update the script to remove the "TF_" string in the variables and update the "Publish Build Artifacts" step to publish the files in "BUILD_BINARIESDIRECTORY" folder(Set Path to Publish to: $(Build.BinariesDirectory)).
However, if you want to copy and publish the website files, you can simply add one more argument in "MSBuild Arguments" section of "Visual Studio Build" step:
"/p:outdir=$(build.artifactstagingdirectory)"
Remove the Power-Shell script step and the other steps just keep default settings.
Or you can also change the settings of "Copy Files" steps to select the files/folders you'd like to copy.

How to create MSdeploy Package using MSBuild for all files in this project folder

I'm trying to create a web deploy package using msbuild through command line. I have been searching all over and found the following command
msbuild myproject.csproj /t:package
Though it works for me but it gives me only what visual studio gives us back when we create web deploy package through Packge/Publish Web tab with "only files needed to run this application" option selected from the drop down menu. But I want my web deploy package to look exactly the same as what I get when I select "All files in this project folder" option from the drop down menu. I have gone through links like this http://sedodream.com/2010/05/01/WebDeploymentToolMSDeployBuildPackageIncludingExtraFilesOrExcludingSpecificFiles.aspx.
But I wonder that do I really need to customize my .csproj file (the way its been described in that post) since all I want, is a command line (apparently more elaborate than the one I mentioned above) for msbuild that can imitate the "All files in this project folder" option that populates the "bin folder of web deploy package" with all the .dlls that are there in the original bin folder of my project and generate me a more comprehensive package.
In your commandline simply add /p:FilesToIncludeForPublish=AllFilesInProjectFolder to your msbuild invocation. While you're at it, you may also want to pass in a specific configuration to build /p:Configuration=Release
So:
msbuild myproject.csproj /t:package /p:FilesToIncludeForPublish=AllFilesInProjectFolder /p:Configuration=Release
Tip: Many of these settings are stored in your project file. Open up your file in Notepad and compare the changes made when you have changed some settings. Any item that's in a <propertygroup> can usually be passed along through the commandline as well using the /p: parameter.

How to get Visual Studio 'Publish' functionality to include files from post build event?

I am currently attempting to use Visual Studio 2010 'Publish' and MSDeploy functionality to handle my web deployment needs but have run into a roadblock with regards to customizing the package depending on my build configuration.
I develop in a 32bit environment but need to create a release package for a 64bit environment, so in the 'Release' configuration I have a post build event that copies the 64bit version of a third-party dll into the bin directory overwriting the 32bit version. When I use the 'Publish' functionality, even though the correct 64bit dll is being copied to the bin directory, it doesn't get included in the package.
Is there a way to get the 'Publish' to include files that have been copied into the bin directory during a post build event?
I answered a similar but different question at How do you include additional files using VS2010 web deployment packages?.
In your scenario you are using post build event, I would recommend dropping the post build event and implement your actions using your own MSBuild targets instead of post build event. Below you'll find the text of the other answer.
From: How do you include additional files using VS2010 web deployment packages?
Great question. I just posted a very detailed blog entry about this at Web Deployment Tool (MSDeploy) : Build Package including extra files or excluding specific files.
Here is the synopsis. After including files, I show how to exclude files as well.
Including Extra Files
Including extra files into the package is a bit harder but still no bigee if you are comfortable with MSBuild, and if you are not then read this. In order to do this we need to hook into the part of the process that collects the files for packaging. The target we need to extend is called CopyAllFilesToSingleFolder. This target has a dependency property, PipelinePreDeployCopyAllFilesToOneFolderDependsOn, that we can tap into and inject our own target. So we will create a target named CustomCollectFiles and inject that into the process. We achieve this with the following (remember after the import statement).
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
This will add our target to the process, now we need to define the target itself. Let’s assume that you have a folder named Extra Files that sits 1 level above your web project. You want to include all of those files. Here is the CustomCollectFiles target and we discuss after that.
<Target Name="CustomCollectFiles">
<ItemGroup>
<_CustomFiles Include="..\Extra Files\**\*" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>Extra Files\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
Here what I did was create the item _CustomFiles and in the Include attribute told it to pick up all the files in that folder and any folder underneath it. Then I use this item to populate the FilesForPackagingFromProject item. This is the item that MSDeploy actually uses to add extra files. Also notice that I declared the metadata DestinationRelativePath value. This will determine the relative path that it will be placed in the package. I used the statement Extra Files%(RecursiveDir)%(Filename)%(Extension) here. What that is saying is to place it in the same relative location in the package as it is under the Extra Files folder.
Excluding files
If you open the project file of a web application created with VS 2010 towards the bottom of it you will find a line with.
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
BTW you can open the project file inside of VS. Right click on the project pick Unload Project. Then right click on the unloaded project and select Edit Project.
This statement will include all the targets and tasks that we need. Most of our customizations should be after that import, if you are not sure put if after! So if you have files to exclude there is an item name, ExcludeFromPackageFiles, that can be used to do so. For example let’s say that you have file named Sample.Debug.js which included in your web application but you want that file to be excluded from the created packages. You can place the snippet below after that import statement.
<ItemGroup>
<ExcludeFromPackageFiles Include="Sample.Debug.xml">
<FromTarget>Project</FromTarget>
</ExcludeFromPackageFiles>
</ItemGroup>
By declaring populating this item the files will automatically be excluded. Note the usage of the FromTarget metadata here. I will not get into that here, but you should know to always specify that.
I found a workaround for the problem by using the ExcludeFilesFromDeployment element within the project file. I got the idea from Web Deployment: Excluding Files and Folders
So if you need to package project files as they exist in your project directory after a successful build and associated post build steps then do the following.
Edit "Package/Publish Web" project settings and
select Items to deploy to be "All files in this project folder"
Unload the project
Right click on the unloaded project and select to edit the project config
Locate the PropertyGroup element associated to the configuration setting e.g. "Release"
Within the PropertyGroup element add in the following elements and exclude files and folders you don't want in the package
<ExcludeFilesFromDeployment>*.cs;**\.svn\**\*.*;Web.*.config;*.csproj*</ExcludeFilesFromDeployment>
<ExcludeFoldersFromDeployment>.svn;Controllers;BootstrapperTasks;Properties</ExcludeFoldersFromDeployment>
Save and reload your project
This solves my problem for the time being but if there is a better solution then please let me know, as this is not ideal due to the hackery involved, but then again perhaps this is an uncommon deployment scenario?
Select your files or folders and Change Build action as Content from Properties Window.
I know its a old question but none of these worked for me .
In 2017 VS I just right clicked on the extra folder to be published and select publish it worked.
Example:
Adding the bin folder (and it's contents) to the project caused the files to be copied to the publish output directory.
For me, my issue was that I needed to place a proprietary software license file in the bin/ folder, but did not want to copy it manually each deployment.
This was using Visual Studio 2015 Professional
I know this is an old conversation but I came upon it while trying to do the same thing and I thought it would be helpful to add what I found here.
Nearly all the articles about including extra files in your publication use this method of adding the CopyAllFilesToSingleFolderForPackageDependsOn or CopyAllFilesToSingleFolderForMSDeployDependsOn items in the PropertyGroup and they all same something like "I added this to the end of the file ..."
This is what I did and spent an afternoon trying to find why nothing was happening until I realised there was already a PropertyGroup section at the top of the file. When I put my CopyAllFilesToSingleFolderForPackageDependsOn into that section it worked fine.
Hope this saves someone time some day

Resources