Can TeamCity publish a Web project using the sln2008 build runner? - asp.net

I'm building an ASP.Net MVC project in TeamCity.
Can I somehow call the Publish target and get the output copied to a folder under IIS? or do I need to write an msbuild script for this?

I've written a pretty long blog post on this very topic that may interest you:
http://www.diaryofaninja.com/blog/2010/05/09/automated-site-deployments-with-teamcity-deployment-projects-amp-svn
basically:
install web deployment projects
add web deployment project to your solution
setup the solution configuration manager to have a "Deployment" build configuration
get team city to use this build switch when running the build
have a beer and wonder in glory at your automagical awesomenesss

Have you tried a Web Deployment Project (WDP)? I have multiple Web Application Projects (WAP) with associated WDPs that work great with TeamCity for deployment scenarios.
I use the sln2008 runner to build my solution (containing both the WAP and the WDP). I've modified the WDP project file (an MSBuild script) to copy the output to a network share:
<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Deploy' ">
<!-- copy WDP output to \\build02\wwwroot\Belden.Web.Intranet\ -->
<ItemGroup>
<MySourceFiles Include="$(OutputPath)**\*.*" />
</ItemGroup>
<Copy SourceFiles="#(MySourceFiles)" DestinationFiles="#(MySourceFiles->'\\build02\wwwroot\Belden.Web.Intranet\$(ProjectDir)%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
I haven't tried this with MVC/WDP, but I imagine it would work the same ...

I believe you can: Publish sln. Have a look at the targets. Hopefully it will lead you in the right direction.

I also had a look at this a while ago but could but had no luck with publishing targets, maybe because my IIS resided on a different server.
Here is how I did it anyway, hope it helps TeamCity deletes files on build have a look at the accepted answer.

Related

How to copy appsettings.json to DEBUG folder, as part of dotnet build

I am having a console application, which is using appsettings.json for holding the configuration values.
In Visual Studio IDE , when I set AlwaysCopy for appsettings.json, it will be copied to the DEBUG folder, as part of BUILD.
But, in .net core, when I run dotnet build, it is not copying appsettings.json to DEBUG folder.
I am already having below xml configuration added to .csproj
<Content Include="appsettings.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
When I do dotnet publish, it is getting copied to publish folder. But, it is not happening when I do dotnet build. Can you please tell, why it is not happening & what should I do to copy the appsettings.json to DEBUG folder?
Found the answer in another thread is Stackoverflow(The difference between build and publish in VS?). In .NET Core, build & publish are different, as compared to .NET Framework.
Building .NET Framework applications will generate the same files as
Publish. It will create all the dependencies as binaries including
external dependencies(NuGets for instance). So the product of dotnet
build is ready to be transferred to another machine to run
Building .NET Core applications, if the project has third-party
dependencies, such as libraries from NuGet, they're resolved from the
NuGet cache and aren't available with the project's built output.
Therefore the product of dotnet build isn't ready to be transferred to
another machine to run. You need to run Publish to get all 3rd party
dependencies as binaries in output folder.
If we want a file to be part of publish, we need to add below attribute. In build, this file is not copied to the DEBUG/RELEASE folder.
<Content Include="appsettings.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>

MSbuild Website Not Publishing to Local Directory

I need to publish a .NET web site project to a local directory. The web site project is part of a solution that also contains a web app. The Publish Web App option in Visual Studio publishes the web site to the directory without issue, however I am unable to publish the site through msbuild.
My msbuild command
msbuild "C:\...\ProjectName\website.publishproj" /p:deployOnBuild=true /p:publishProfile=Dev /p:PrecompileBeforePublish=false /p:VisualStudioVersion=14.0 /p:WebPublishMethod=FileSystem
The dev.pubxml publish profile I am referencing is:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>True</ExcludeApp_Data>
<publishUrl>C:\FolderLocation</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
<ExcludeFoldersFromDeployment>.vs</ExcludeFoldersFromDeployment>
</PropertyGroup>
</Project>
Currently the web site is not publishing to C:\FolderLocation but instead appears to publish to ProjectName\PrecompiledWeb\localhost_51636. Changing the output directory via /p:OutDir=C:\FolderLocation publishes the web app to the correct location, however it does not publish the web site. I have also tried both /p:PublishDestination and /p:DesktopBuildPackageLocation msbuild arguments however the original issue remains.
I have referenced Publish Artifacts for website goes to PrecompiledWeb and many other resources. My eventual goal is to setup CI through Azure Devops for the entire legacy .NET website project.
With TFS - it is using MSBUILD under the covers and we need this parameter to write to a directory for artifacts to be pulled from
/p:OutDir=$(build.StagingDirectory)
You are telling it only about the Publish Project part - see if putting your SLN file there at the first parameter solves it and does all of them.

Visual Studio .NET publish - How to run a command before "Publish" that generates code

I am using Visual Studio 2012 and am working with a JavaScript framework (Ext JS). My HomeController basically redirects to the index that Ext JS uses. It communicates with other Visual Studio projects that actually make use of .NET (via CORS), but this particular project just contains my JavaScript application.
I want to publish this Visual Studio project, but there is a catch. A tool that is used with Ext JS, named Sencha Command, is used to create a production version of the JavaScript application. It basically creates a stand-alone build folder that contains all the JavaScript scripts combined and minified, required resources, compiled Sass, etc. It works out really well in some scenarios, but I am not sure how to make it play nice with Visual Studio on publish.
I have figured out how to get the sencha command to run with a post-build command that checks to see if I am in debug mode or not, but I don't want the generated folder to be part of my actual project, and I don't want the not-yet-compiled code to be published either. I know how to omit a folder in my pubxbml file. But I need to do something like move the build folder to the publish location.
Has anyone encountered scenarios such as this? Is there a better way to go about this?
Here is my current pubxml:
<?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>FileSystem</WebPublishMethod>
<SiteUrlToLaunchAfterPublish />
<publishUrl>C:\Users\TestUser\Desktop\Release</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
<ExcludeFoldersFromDeployment>
js/ext;js/App
</ExcludeFoldersFromDeployment>
</PropertyGroup>
<Target Name="BeforePublish" BeforeTargets="FileSystemPublish">
<Exec Command="echo Hello" />
</Target>
</Project>
Note: I don't think the BeforePublish worked. I tried a number of commands there, including the "sencha app build" command which I later moved to a post-build command.

MSBuild failing to build referenced projects when upgrading to VS2010

I have recently upgraded my .Net 3.5 solution containing some C# code projects and a ASP.net web site project to VS2010 (from VS2008). It is building and running fine inside VS, but I get some problems when trying to build it on my server with MSBuild 4.0 via TeamCity. It seems like the projects that are referenced from the web site are not built. This was all working fine before I upgraded to VS2010, MSbuild 4.0 and Windows SDK 7.1.
Inside the msbuild script that I use to build from teamcity I have defined project references for the web site like this:
<ProjectReference Include="..\src\trunk\DataAccess\DataAccess.csproj">
<Project>{C43242F4-7286-4BEC-9A27-001D6FC14860}</Project>
<Name>DataAccess</Name>
</ProjectReference>
When I try to run the build script I get an error message saying that it could not find the dll file when trying to copy it from the bin folder of the referenced project into the bin folder of the web site. This is happening because the referenced projects are in fact never built at all (No bin folder exists in the project dir).
Does anyone have a clue what may cause this? I am not very experienced with MSbuild, so I may have overlooked some important stuff. Is it not so that MSbuild will automatically try to build the referenced projects if no project output is existing?
Will be thankful for any help!
I would need some more info to guide you on this, but off the top of my head try adding
/toolsversion:3.5
to your msbuild call.
I found another post on this website describing your exact same problem. I also ran into this same problem too.
This blog on the MSDN Website describes the problem and the work-around. Basically it's a limitation of solution files which are not in an MSBuild format, but just a fancy text file. And the real thing is, that the dependencies need to be specified in the project files them selves not the solution file. ahhh... just read the link it explains it a hundred times better than my answer here.

How to build silverlight website & create XAP's using script?

I am just getting started with Silverlight and have recently added a Silverlight project to an established solution. In this particular scenario my solution included an existing ASP.NET web site which Visual Studio kindly offered to integrated my Silverlight application into, which I accepted.
So everything is fine and all, and the Silverlight XAP is being copied to the web site's ClientBin directory when i was buiding solution through visual studio, But
I want same thing through using nant script when i am used nant script that time all project in the solution are build but recenty added silverlight website do not create XAP's in ClientBin dierctory.
I m using following script :-
target name="build" description="compiles the source code">
exec program="${framework::get-framework-directory(framework::get-target-framework())}
\msbuild.exe" commandline="MY.sln" workingdir="ProjectFolder" />
what are the ways ??
You could reverse-engineer the MsBuild scripts used to build Silverlight apps and .Xap files, the files will be located in:
C:\Program Files (x86)\MSBuild\Microsoft\Silverlight\v3.0
Your msbuild compilation should be creating the XAP file in the Bin\Debug folder of the silverlight project. You can simply use the Nant copy task to move it to the Web project's ClientBin folder.

Resources