When using TeamCity to compile my MSBuild XML task script, it fails with this:
[10:43:03]: myWebProject1\ myWebProject 1 .csproj (3s) [10:43:07]: [ myWebProject1\ myWebProject1 .csproj] _CopyWebApplicationLegacy [10:43:07]: [_CopyWebApplicationLegacy] Copy [10:43:07]: [Copy] C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets(131, 5): error MSB3021: Unable to copy file "obj\Release\myWebProject1.dll" to "C:\MSBUILDRELEASE\myWebProject1\\bin\myWebProject1.dll". Could not find file 'obj\Release\myWebProject1.dll'.
When I run it locally, it works.
When I compare my local output to my build server output, there are files missing on my build server. Like the global.asax file is missing from my build server output directory (but not when I compile this locally). Why is that?
Here is my current MSBuildScript:
<?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Build"> <PropertyGroup> <OutputDir>C:\MSBUILDRELEASE</OutputDir> </PropertyGroup> <ItemGroup> <ProjectToBuild Include="UtilityApp.sln" > <Properties>OutputPath=$(OutputDir);Configuration=MSBuildRelease;Platform=x86</Properties> </ProjectToBuild> </ItemGroup> <Target Name="Build"> <MSBuild Projects="@(ProjectToBuild)"/> <CallTarget Targets="Publish WebProject1" /> <CallTarget Targets="Publish WebProject2" /> </Target> <Target Name="Publish WebProject1"> <RemoveDir Directories="$(OutputFolder)" ContinueOnError="true" /> <MSBuild Projects="WebProject1\WebProject1.csproj" Targets="ResolveReferences;_CopyWebApplication" Properties="WebProjectOutputDir=$(OutputDir)\WebProject1\; OutDir=$(OutputDir)\WebProject1\;Configuration=Release;Platform=AnyCPU" /> </Target> <Target Name="Publish WebProject2"> <RemoveDir Directories="$(OutputFolder)" ContinueOnError="true" /> <MSBuild Projects="WebProject2\WebProject2.csproj" Targets="ResolveReferences;_CopyWebApplication" Properties="WebProjectOutputDir=$(OutputDir)\WebProject2\; OutDir=$(OutputDir)\WebProject2\;Configuration=Release;Platform=AnyCPU" /> </Target> </Project>
I can run this script locally and it seems to work fine (no errors generated). When I run it on my build server, it fails with MSBuild error MSB3021.
Now when I compare my local build output files to my server build output files, the server output does not have as many files. For instance, the global.ASAX file is missing in the output on my buildserver. Why would it work local for me, but not on my TeamCity build server? What's the difference and how can I fix it?
I noticed the TeamCity build agent error message has a funny directory path: "C:\MSBUILDRELEASE\myWebProject1\bin\myWebProject1.dll"
^ There are two slashes before the bin folder. I do not specify that anywhere. What gives? I have a feeling I am not building my Web Projects correctly (maybe use a different task approach?). It seems to work locally but not on my build server.
Am I building my web projects correctly? These are simply web projects for Web Service (ASMX) deployment. Help?
Alright, I figured it out. It's a "Configuration" mismatch. You have one project building with Configuration=MSBuildRelease and two other projects building with Configuration=Release. MSBuild then looks in the wrong place for the "intermediate" assemblies.
Change your code to this:
<?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Build"> <PropertyGroup> <OutputDir>C:\MSBUILDRELEASE</OutputDir> </PropertyGroup> <ItemGroup> <ProjectToBuild Include="UtilityApp.sln" > <Properties>OutputPath=$(OutputDir);Configuration=MSBuildRelease;Platform=x86</Properties> </ProjectToBuild> </ItemGroup> <Target Name="Build"> <MSBuild Projects="@(ProjectToBuild)"/> <CallTarget Targets="Publish WebProject1" /> <CallTarget Targets="Publish WebProject2" /> </Target> <Target Name="Publish WebProject1"> <RemoveDir Directories="$(OutputFolder)" ContinueOnError="true" /> <MSBuild Projects="WebProject1\WebProject1.csproj" Targets="ResolveReferences;_CopyWebApplication" Properties="WebProjectOutputDir=$(OutputDir)\WebProject1\; OutDir=$(OutputDir)\WebProject1\;Configuration=MSBuildRelease;Platform=AnyCPU" /> </Target> <Target Name="Publish WebProject2"> <RemoveDir Directories="$(OutputFolder)" ContinueOnError="true" /> <MSBuild Projects="WebProject2\WebProject2.csproj" Targets="ResolveReferences;_CopyWebApplication" Properties="WebProjectOutputDir=$(OutputDir)\WebProject2\; OutDir=$(OutputDir)\WebProject2\;Configuration=MSBuildRelease;Platform=AnyCPU" /> </Target> </Project>
After spending 3 hours on this bug, I started a new project and I imported each file from the old project one by one. I've been able to compile between each file until I added the last file.
I thought the problem was related to that last file but I realized by removing other files that this issue was happening only when I had a specific number of files included in my project.
I can't tell why it worked, but I solved this issue by adding / removing empty classes with random names to my project.
After a couple of Add / Compile / Remove / Compile again, VS started to work correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With