My goal : add dlls coming from other projects and publish the web app with those files in the bin folder.
So I try to publish extra dll files not included in my main web project. I need to do this because several class library projects are not referenced. Those projects have post-build events that copy their own dlls in the main web project folder (I read them with DI thanks to Autofac). Locally it works well if I publish all the folders, but when I want to publish the main web project, the extra dlls are not there.
And I need to use it with TeamCity cause I want to publish automatically at every commit. This part works, the only problem is that the extra dll files are not published.
Some interesting links :
- http://sedodream.com/2010/05/01/WebDeploymentToolMSDeployBuildPackageIncludingExtraFilesOrExcludingSpecificFiles.aspx
- http://cgeers.com/2011/06/04/using-a-msbuild-script-in-teamcity/
- http://www.troyhunt.com/2010/11/you-deploying-it-wrong-teamcity.html
I tried to :
- Create a MSBuild file to insert DLLs dynamically > failed
- Add pre/post build/publish events > failed, the class library projects are compiled after the main one
- Change build order > failed cause depends on dependencies (I want the main project to ignore all the other ones)
What could I try now? Any help would be greatly appreciated.
UPDATE
I tried to add custom files (found here: http://blog.samstephens.co.nz/2010-10-18/msbuild-including-extra-files-multiple-builds/), here is my build file. I launch the BuildAll target in TeamCity.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WorkingFolder>$(MSBuildProjectDirectory)</WorkingFolder>
<SolutionFile>..\Project.sln</SolutionFile>
<TargetFolder>..\Project.MvcApp\bin</TargetFolder>
<Configuration>Release</Configuration>
</PropertyGroup>
<Target Name="BuildAll" DependsOnTargets="Compile">
<Message Text="=== BuildAll: $(Configuration) configuration ===" />
</Target>
<Target Name="Compile">
<Message Text="=== Compile: $(Configuration) configuration, $(WorkingFolder) working folder ===" />
<MSBuild Projects="$(SolutionFile)" Properties="Configuration=$(Configuration)" />
</Target>
<Target Name="DefineCustomFiles">
<ItemGroup>
<CustomFilesToInclude Include="..\Project.Login\bin\Project.Login.dll" />
<CustomFilesToInclude Include="..\Project.Login\bin\$(Configuration)\Project.Login.dll" />
</ItemGroup>
</Target>
<Target Name="CustomCollectFiles">
<ItemGroup>
<FilesForPackagingFromProject Include="@(CustomFilesToInclude)">
<DestinationRelativePath>$(TargetFolder)\%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
DefineCustomFiles;
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
</Project>
Project.MvcApp is the main MVC application, Project.sln is the global solution file and Project.Login the project I want the dll to be inserted in the publication.
What am I doing wrong here? :(
UPDATE
The solution is to insert the custom targets at the end of your .csproj file. Here is another thread focused on the problem: DefineCustomFiles and CustomCollectFiles are not fired by TeamCity
If you add the dlls (instead of the projects) as references, and set them to copy always, you should get what you want. How to get the dlls where you want them is another question. I think these are your options:
- build the dependent projects in the same build
- build the dependent projects in a different build which submits the dlls to source control
- depend on the developers to check in the dlls whenever the dependent projects change. -
In my current project we use a combination of the first and third solution which works fine for us since the dependent dlls don't change very often. BTW, we don't use msbuild directly for publishing, we use the devenv command line with /publish.
Hope this helps!
来源:https://stackoverflow.com/questions/16969883/publish-extra-dll-files-not-included-in-the-web-project