简体   繁体   中英

Why am I missing assemblies from the bin directory when compiling with MsBuild?

I have a solution which contains many class libraries and an ASP .NET website which references those assemblies.

When I build the solution from within the IDE, all assemblies referenced by the website end up in the bin directory. Great!

When I use MsBuild from the command line, all the referenced assemblies are not copied to the bin directory. Why?

My command line is simply:

msbuild.exe d:\myproject\mysolution.sln

The issue I was facing was I have a project that is dependent on a library project. In order to build I was following these steps:

msbuild.exe myproject.vbproj /T:Rebuild
msbuild.exe myproject.vbproj /T:Package

That of course meant I was missing my library's dll files in bin and most importantly in the package zip file. I found this works perfectly:

msbuild.exe myproject.vbproj /T:Rebuild;Package

I have no idea why this work or why it didn't in the first place. But hope that helps.

I have found various references to this problem scattered around the Net - and I've just come across it myself. Apparently MSBuild on the command line isn't as good at tracing chains of dependencies as the IDE is.

So as I understand it, if A depends on B which depends on C, The command line may not realize that A depends on C.

The only solution I've found is to ensure that you manually set the project dependencies so that the ASP project references everything it depends on - don't expect it to be able to figure them all out on the command line. This has worked for me, although I only have 5 projects so it's not a bind to get going.

I hope this helps.

Known problem ffor MSBuild 3.5 and msbuild 4.5. I am using Msbuild 4 found at

 c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe <yourSolutionFile>.sln

It seems to solve the problem.

You could make use of the Post-Build steps in project properties to copy the output for the project to a particular location.

This copies to an Assemblies directory in the same directory as the Sln file. I have this in the post-build step of all my projects.

md "$(SolutionDir)Assemblies"
del "$(SolutionDir)Assemblies\$(TargetFileName)"
copy "$(TargetPath)" "$(SolutionDir)Assemblies" /y

Which msbuild are you referencing? Is it the right one?

I generally call like this (from a batch file):

%WINDIR%\\Microsoft.NET\\Framework\\v3.5\\msbuild.exe deploy.proj /v:n

In this example, deploy.proj is just a regular msbuild file that does some other stuff before and after calling msbuild on the .sln file.

I think this problem only occurs when your bin directory is not the framework's default for a solution.

I understand that msbuild uses each project set up to build it. If this is so, please go to each projects properties page and check the post build event command line arguments.

You could always use a copy task in MSBuild to pull your assemblies into the proper directory. I asked a question not to long ago and ended up answering it myself. It shows how you can setup your Copy task to grab output from another project and pull it into your target project:

MSBuild copy output from another project into the output of the current project

I haven't been using msbuild for ASP.NET, but aspnet_compiler. Though...I don't remember why. Sorry.

%windir%\Microsoft.Net\framework\v2.0.50727\aspnet_compiler -v \%~n1  -f -p .\%1 .\Website

If I recall, MSBuild dosen't copy the referenced assemblies. I've posted a "solution" a while ago: http://www.brunofigueiredo.com/post/Issue-Tracker-part-IV-The-Build-Enviroment-using-MSBuild-(or-NAnt).aspx

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM