svc, xml are not being deployed - wcf

I'm having problem with publishing WCF service from CI (Cruise Control)..
Let's say I have a WCF project called "WCF-A". I put the following lines in csproj of "WCF-A"
<Target Name="BeforeBuild">
<Message Text="##############Before build##################" Importance="high" />
<RemoveDir Directories="publish" ContinueOnError="true" />
</Target>
<Target Name="AfterBuild">
<Message Text="##############After build##################$(OutputFolder)" Importance="high" />
<MSBuild Projects="$(ProjectName).csproj" Targets="ResolveReferences;_CopyWebApplication" Properties="WebProjectOutputDir=publish\;OutDir=publish\bin\" />
</Target>
I'm using the following to build my service from commandline. (Note that we are using CI but in order to make my question simple, I will use commandline. )
E:\..\Code\>msbuild MyServices.sln /t:Clean;Rebuild
It works perfectly and all assemblies, cross-domain xml, svc files are published under "publish" folder.
The problem come out when I add another services (let's called it "WCF-B") in the solution file. [Edit] I added the same "BeforeBuild" and "AfterBuild" in WCF-B as well. [/Edit] I project-referenced WCF-A from "WCF-B"... but when I build the solution with the same command that I used, the publishing for "WCF-B" is working fine. But the cross-domain file and svc file of "WCF-A" are not being deployed anymore. Only assembly of "WCF-A" are being published under "publish\bin" folder.
Do you guys have any idea why it's happening like that? Thanks in advance.
Edit
I think having "project-reference" creates this problem.. But I need to project-reference instead of calling the service from proxy class. Since both services will be hosted on the same server, I prefer dll-reference over service-calls.

It looks as if the files of WCF-A are being deleted by the BeforeBuild target of WCF-B (assuming that the publish directory resolves to the same directory) and that the assembly WCF-A cannot be deleted because it is referenced by WCF-B and in use.
You might try to increase the log verbosity using /v:d or even /v:diag for further information.
E:\..\Code\>msbuild MyServices.sln /t:Clean;Rebuild /v:d

Related

msbuild copies whole drive

Would really like help with this.
I'm running Team City, have setup a build config, it builds fine. I added a deploy parameter, and that functions almost correctly. The thing is it's trying to deploy my entire c-drive!
This is the config for it:
<Target Name="DeployApp">
<Message Text="Copying application files..." />
<ItemGroup>
<ApplicationFiles Include="$(ApplicationOutputDirectory)\**\*.*" />
</ItemGroup>
<Copy SourceFiles="#(ApplicationFiles)" DestinationFolder="$(DestinationPath)\% (RecursiveDir)"/>
</Target>
Any help on how to make it only copy the built project to the server?
If $(ApplicationOutputDirectory) isn't set, the Include statement will resolve to \**\*.*, which is the entire current drive (in this case, your C drive)

Config transformation in WIX setup

I'm creating a MSI setup with WIX for my Web Application. This works correct. The only thing that I don't get to work is to enabling the config transformation of the standard web application publish method.
I understand that you can add the using tag for existing target files. I try'ed to add the TransformXml to the AfterBuild Target in the project file of the WIX installer but that doesn't work.
<TransformXml Source="Web.Config" Transform="Web.$(Configuration).config" Destination="Web.Config" />
Can someone help me?
I created a test project for this called WebApplicationWix
I didn't see any mention of TransformXml in your example project.
You need code similar to this:
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterCompile">
<CallTarget Targets="TransformWebConfiguration" Condition="Exists('web.$(Configuration).config')"/>
</Target>
<Target Name="TransformWebConfiguration">
<!-- Generate transformed web configuration -->
<TransformXml Source="web.config" Destination="web.transformed.config" Transform="web.$(Configuration).config" />
</Target>
A few things to note:
Check the path to Microsoft.Web.Publishing.Tasks.dll in the UsingTask element (change for your version of Visual Studio)
In your example, the source and destination were the same; you should make sure the destination is a different file so that you don't have file lock issues or overwrite the web.config you're trying to transform with the transformed one.
In Visual Studio 2010, there were file locking issues with TransformXml, so be careful of that if you're using 2010.

MSBuild Issue while deploying files

I am deploying some files on the server. But when I am doing this, build is deleting all the files and folder which are residing at that location. I don't want to delete all the files from the server. I want to exclude one folder (folder name is Temp) from the destination folder. Temp folder should not get deleted while deleting other files. How to do that?
Here is TFS Build Definition
<PropertyGroup Condition=" '$(DeployEnvironment)' == 'Dev' ">
<DeployPath>\\server1\D$\temp\reports</DeployPath>
</PropertyGroup>
<Target Name="CoreCompileSolution" />
<Target Name="AfterCompile">
<Message Importance ="high" Text="Solution Root: $(SolutionRoot)" />
<Message Importance ="high" Text="Out Dir: $(OutDir)" />
<Copy SourceFiles="#(RPTFiles)" DestinationFolder="$(OutDir)_PublishedWebsites\Reports\" />
</Target>
<Target Name="AfterDropBuild" >
<CreateItem Exclude="$(DeployPath)\Temp*.*">
<Output ItemName="PreviousDeployment" TaskParameter="Include" />
</CreateItem>
</Target>
Why are you using a Copy task? I think it is intended to be used for local manipulations during build, rather than deployment (because it does not give you a chance to easily configure behaviour).
I suggest that instead of copy tsak you use one of the following options
Non-web applications - use Robocopy:
/XD dirs [dirs]... : eXclude Directories matching given names/paths.
XF and XD can be used in combination e.g.
ROBOCOPY c:\source d:\dest /XF *.doc *.xls /XD c:\unwanted /S
see this link for usage guide. You either run it from the command line (using <Exec Command="" > task, or employ MBuiild Community Tasksproject which has a nice wrapper.
Web applications: you should use Web Deploy for your deployments. You an either use MSBuild integration (VS 2010 and later, see this blog series for guidance on setup and configure on VS2010 NB: it has been much simplified in VS 2012, but I don't have a link to share at the moment) or run it from command line (prior to VS 2010):
<Exec Command=""$(WebDeployToolPath)" -verb:sync - source:dirPath='$(MSBuildProjectDirectory)\Published\' -dest:dirPath='$(DeployDirectoryLocalPath)',computerName=$(DeployTargetURL),userName='$(DeployUserName)',password='$(Password)',authType='Basic' -skip:skipaction='Delete',objectname='filePath',absolutepath='app_offline.htm' -skip:skipaction='Delete',objectname='filePath',absolutepath='logs\\.*' -skip:skipaction='Delete',objectname='dirPath',absolutepath='logs\\.*' -skip:skipaction='Delete',objectname='filePath',absolutepath='UserFiles\\.*' -skip:skipaction='Delete',objectname='dirPath',absolutepath='UserFiles\\.*' -verbose -allowUntrusted" />
NB using skip:skipaction='Delete.. to skip removing files and folders.
Update
It looks like I've undestood this a bit incorrect (I supposed, deployment happenned in AfterCompile target, however, as I see now, TFS uses CoreDropBuild target to do the deployment.
So I think, what you need is to override CoreDropBuild target as described: here. (although, I've never tried this).
You can either use Copy task as the author of the thread, or go with Robocopy/webdeploy based on your personal preference.

working with paths in msbuild

I'm trying to setup a virtual directory using msbuild and the msbuild community tasks but cannot find a way how to specify a relative path which is outside the $(MSBuildStartupDirectory).
My project is structured like this:
c:\proj\
src\
website (this is where the virtual dir should point to)
build\
build.proj (this is the msbuild file)
What I'd like to do is something like this (note that $(MSBuildStartupDirectory) points to c:\proj\build):
<WebDirectoryCreate
VirtualDirectoryName="website"
VirtualDirectoryPhysicalPath="$(MSBuildStartupDirectory)\..\src\website" />
Unfortunately this doesn't work - the '..' is not resolved and and the virtual dir then points to c:\proj\build\..\src\website.
Can anyone point me a hint how to work with (relative) paths in msbuild?
I tried that and it worked fine for me. I tested this on Windows XP using msbuild 4.0 and community tasks version 1.3.0.504.
I usually use MSBuildProjectDirectory since MSBuildStartupDirectory could be pointing elsewhere depending on how msbuild got executed.
The example below will create the web site and remove the .. entries from the path by using the FullPath metadata.
<ItemGroup>
<WebPath Include="$(MSBuildProjectDirectory)\..\src\website" />
</ItemGroup>
<Target Name="CreateWeb">
<Message Text="WebPath=#(WebPath)" Importance="high" />
<Message Text="FullPath=%(WebPath.FullPath)" Importance="high" />
<WebDirectoryCreate
VirtualDirectoryName="website"
VirtualDirectoryPhysicalPath="%(WebPath.FullPath)" />
</Target>

MSBuild doesn't respect PublishUrl property for my ClickOnce app

I'm trying to make a batch file to publish the few ClickOnce application we have in one click. I'm using msbuild for that, and as an example the below command line shows how I'm doing it:
msbuild
MyApp.sln
/t:Publish
/p:Configuration=Release
/p:PublishUrl="C:\Apps\"
/v:normal > Log.txt
(wrapped for easier reading)
when I run the above command it builds and publish the application in the release directory, i.e. bin\release! Any idea why msbuild doesn't respect PublishUrl property in my example above?
PS: I tried also different combinations including remove 'Configuration', use 'Rebuild' and 'PublishOnly' as targets, and remove the the quotation marks but without any success.
You are setting the wrong property. Try PublishDir instead.
You can pass it into MSBuild as you are or you can set it in the project file (or maybe the sln file too, not sure I always use the project file.) like this
<PropertyGroup>
<PublishDir>C:\Dev\Release\$(BuildEnvironment)\</PublishDir>
</PropertyGroup>
I've just done a few blog posts on MsBuild and ClickOnce stuff, check it out you 'should' find them useful...
Some features are done by Visual-Studio and not by the MSBuild-script. So the click-once-deployment behaves differently when it's executed from the command-line.
The ApplicationRevision isn't increased with every build. This works only when is exectued from Visual Studio
In in somecases, the PublishUrl isn't used. Quote from MSDN:
For example, you could set the PublishURL to an FTP path and set the InstallURL to a Web URL. In this case, the PublishURL is only used in the IDE to transfer the files, but not used in the command-line builds. Finally, you can use UpdateUrl if you want to publish a ClickOnce application that updates itself from a separate location from which it is installed.
I've created a special MSBuild-file which does this things. It runs the publish-target and copies then the files to the right location.
An example of the build-file, as requested by alhambraeidos. It basically runs the regular VisualStudio-build and then copies the click-once data to the real release folder. Note that removed some project-specific stuff, so it's maybe broken. Furthermore it doesn't increase the build-number. Thats done by our Continues-Build-Server:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Publish" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- the folder of the project to build -->
<ProjLocation>..\YourProjectFolder</ProjLocation>
<ProjLocationReleaseDir>$(ProjLocation)\bin\Release</ProjLocationReleaseDir>
<ProjPublishLocation>$(ProjLocationReleaseDir)\app.publish</ProjPublishLocation>
<!-- This is the web-folder, which provides the artefacts for click-once. After this
build the project is actually deployed on the server -->
<DeploymentFolder>D:\server\releases\</DeploymentFolder>
</PropertyGroup>
<Target Name="Publish" DependsOnTargets="Clean">
<Message Text="Publish-Build started for build no $(ApplicationRevision)" />
<MSBuild Projects="$(ProjLocation)/YourProject.csproj" Properties="Configuration=Release" Targets="Publish"/>
<ItemGroup>
<SchoolPlannerSetupFiles Include="$(ProjPublishLocation)\*.*"/>
<SchoolPlannerUpdateFiles Include="$(ProjPublishLocation)\Application Files\**\*.*"/>
</ItemGroup>
<Copy
SourceFiles="#(SchoolPlannerSetupFiles)"
DestinationFolder="$(DeploymentFolder)\"
/>
<Copy
SourceFiles="#(SchoolPlannerUpdateFiles)"
DestinationFolder="$(DeploymentFolder)\Application Files\%(RecursiveDir)"
/>
<CallTarget Targets="RestoreLog"/>
</Target>
<Target Name="Clean">
<Message Text="Clean project:" />
<MSBuild Projects="$(ProjLocation)/YourProject.csproj" Properties="Configuration=Release" Targets="Clean"/>
</Target>
</Project>
I'll put in my 2 cents, this syntax seems to work (right or wrong):
/p:publishUrl="C:\\_\\Projects\\Samples\\artifacts\\Web\\"
For me, the soultion was to escape the path.
Instead of:
/p:PublishUrl="C:\Apps\"
Put:
/p:PublishUrl="C:\\Apps\\"