How can I get "Copy output" to get copied to output of an assembly using the library? - msbuild

So in the least clear question title ever, what I'm trying to describe is a situation like so:
Project A, with files that have "Copy output" set to "Only if newer" (or "Always", it doesn't matter in this case).
Project B which has Project A as a dependency.
The files marked as "Copy output" only get copied to Project A's output directory, but I also want them to be copied to Project B, since Project B relies on them.
Is there any way to do this while maintaining MonoDevelop compatibility? (MonoDevelop does not use MSBuild or Mono's equivalent for doing actual builds, so any solution has to be one that doesn't use custom MSBuild steps)

I'm not super familiar with Mono. Do "Post Build Events" work there?
In the properties of ProjectA, go to properties.
Go to "Build Events"
Add this event:
copy $(TargetDir)ProjectAAssemblyName.dll $(ProjectDir)..\ProjectBThirdPartyReferences\ProjectAAssemblyName.dll
Then inside of ProjectB, reference \ProjectBThirdPartyReferences\ProjectAAssemblyName.dll
You may have to tweak the paths a bit.
My advise is to NOT copy ProjectAAssemblyName.dll to the \bin\ folder of ProjectB.
.........

Related

Minimum of MyProject Files needed

I am writing a very basic library in VB.NET
The library just contains classes and modules.
Now in built output I see this files
Application.Designer.vb
Application.myapp
AssemblyInfo.vb
Resources.Designer.vb
Resources.resx
Settings.Designer.vb
Settings.settings
Since I've seen other libraries with only AssemblyInfo.vb file, I was wondering if I can delete the rest.
What is the minimum of files I need here for the lib to work correctly, since I don't have any ressource or setting?
All the files you listed are necessary for a vb.net library project. And these files are generated (in My Project folder) when the project created not the build output files. So you need to keep all the files you listed in order to develop and build your project locally.
And for the files of build output, you can add these files in .gitignore.
When you create a project in VS, you select a predefined template that dictates what gets created. People often become accustomed to seeing the superfluous objects that a given template creates and assume that those objects are mandatory and must be there, However, much of it is not needed.
There is also the Empty Project template (the exact name of this template varies depending on the VS version used).
In VS2017, selection of the template would look like this:
This is a bare-bones project and the Solution Explorer will look like this:
As you can see, there are no pre-loaded references. You will need to add them yourself. About the only thing defined in this template is that you are using the VB language; This project starts out as a WinForm type, so go to the Project Properties->Application tab and change the "Application type" to "Class Library" since you want to create a library.
You may find it useful to start with an Empty Project and add the stuff you normally use and then export the project as new template (in VS2017: Project Menu->Export Template). For more on creating termplates, see: Creating Project and Item Templates
Edit: I just realized that I did not answer your real question about deleting the unused items. I just did a test case and deleted the items under MyProject. I received an error on deletion, but doing a clean/rebuild allowed me to proceed without issues. I would recommend that you backup the project before attempting this on an existing project, but I saw no long term issues in deleting unneeded objects from MyProject.

IntelliJ: generate a JAR but do *NOT* including dependencies

In a simple IntelliJ module, I just want to generate a .jar file with my .class files, via IntelliJ IDE commands.
Please be careful before marking this as a "duplicate":
Although I've seen Google and Stack hits with promising titles, I'm not finding a really good answer, or the title is misleading, or its an unanswered question. I cover one possible answer that I've seen before (below), and why I don't think it's a match.
I've used Eclipse in the past, but I'm rather new to IntelliJ.
I've worked with the "Project Structure / Artifacts" stuff. I can generate the giant jar, similar to using "shade", but it's huge because it includes all the nested dependencies. We want the small jar with just this module's class files because the system we're deploying to already has all the other jars in place.
I've seen some references to changing a target directory in the Artifacts dialog box, but it then talks about references being made in the Manifest file, which I don't want. The destination environment already has its java paths setup, so I'm worried that having jar references in this jar will mess that up. If this really is the answer then I'm confused about how it works.
Constraint 1: Can't use command line tools, since I'm actually walking somebody else through these steps, who likely doesn't have command line tools installed in the path, or wouldn't know how to use them, etc. They're not a coder. (Yes, I know this sounds like an odd scenario; I inherited this situation.)
Constraint 2: We want to keep this as a simple IntelliJ project, vs. converting to Maven or Ant or Gradle, etc.
Coworker had the fix.
Short Answer:
Remove all of the other jars/libraries from Output Layout tab of the Artifacts config dialog.
Longer Answer:
You still do File / Project Structure...
Then in the Project Settings, click Artifacts.
And then you still click the plus button (second column) ti create a new artifact setting.
The trick is the "Output Layout" tab in the third column of the window. Highlight all entries EXCEPT the compiled output of your project and delete all those other entries (click the minus button under that tab, directly above your_project.jar)
On my laptop this causes it to pause for a few seconds; I thought it didn't do anything, then finally it reflected that everything was gone except "'my_module' compile output"
Also check the "Build on make" (for when you later do Build / Rebuild Project)
If you need both a full jar and a slim jar, you can have more than one Artifact configuration with different names, and they will default to different output directories.

Visual Studio 2010 solution - how copy common exe to two main projects?

Situation: An application, that is built into several variations, with different functionality enabled. Each variation has its own main project, with its own output "bin" folder. Call the variations A and B.
There are various common class libraries, which generate dlls. Those all get automatically copied to both output folders. This is working fine.
Now, add another project. It generates an exe, C.exe. It will be loaded as a separate process by the application. (It creates a NamedPipe, providing a ServiceContract via NetNamedPipedBinding.)
When there was only "A" (no "B"), I simply had A and C specify the same output folder.
But now there are TWO places that C needs to go.
For Debug build, must go to A/bin/Debug and B/bin/Debug. Similar for Release build.
The source language is VB, but an answer based on C# projects would almost certainly be adaptable to my situation.
I've written an answer by using XCopy in Post Build Events.
Looking for alternative answers.
Is there a way that is easier to maintain / not dependent on manually entering paths?
My concern is that as variants are added, or moved around, it is necessary to know about the Build Events and manually edit them.
Doing work for a company that is not great at keeping track of such details over the years.
Looking for a way that is less likely to break, or easier for a junior programmer to maintain.
In Project "C", Properties, Post Build Events, use xcopy to copy the .exe and corresponding .pdb. Do this for both the "Debug" configuration and the "Release" configuration of Project C.
(For VB, this is under Compile tab, "Build Events..." button at lower right.)
In project A's Properties, find what its output path is. in this case, the path specified was bin\x86\Debug\. xcopy needs to be told this path, relative to project A inside the solution; this becomes $(SolutionDir)\A\bin\x86\Debug\. The resulting lines, to copy both the exe and its pdb for debugging:
xcopy /y "$(ProjectDir)$(OutDir)*" "$(SolutionDir)\A\bin\x86\Debug\"
This copies ALL files in "C"s output folder to "A"s output folder.
Before adding this line, examine "C"s output folder. Are there any files in it that should not be copied to A? If so, can they be deleted? (And will they STAY deleted, when you rebuild "C"?) If not, you will need to specify more carefully the source files, in xcopy line. Or use multiple xcopy lines, to specify the individual files.
Note the "A", which is the main project being copied to.
Repeat that line for "B".
As more variants of main project are created, add a line for them as well.
If one project specifies a different output path, then the lines need to be correspondingly changed.

Assembly in GAC is not copied to output in project that references a project that references the GAC assembly with CopyLocal=true

I have a "Project A" that references System.Web.Mvc with CopyLocal=TRue.
System.Web.Mvc is in the GAC both on my local maching and on the buildserver.
I also have a "Project B" that references "Project A" in the output for "Project B" System.Web.Mvc is not copied to during the build.
I suspect that this is because it is in the GAC.
Is this true?
And can I do something to make MSBuild copy it to the output folder?
I read the answer from Muse VsExtensions in this thread, which talks about only the direct reference to the GAC, however we have an indirect reference through "Project A":
.NET Reference "Copy Local" True / False Being Set Based on Contents of GAC
This blogpost is also related:
http://deeperdesign.wordpress.com/2010/02/08/msbuild-assembly-dependencies-and-the-gac/
Did you check the .csproj file to verify that the reference does indeed contain the <Private>True</Private> tag? Copy local is unfortunately has 3 states in the xml - True, False and ... missing.
A pragmatic (read hack) solution is that I referenced System.Web.Mvc.dll in "Project B".
This is definitively not the right solution, so please bring me a better solution :-)
One suggestion I've seen floating around for this one is to change all of your projects to have the same output path. This is of limited value though, since if you have a dependency chain like:
Prj B > Prj A > Lib C
Then it's probably because Prj A is shared across multiple applications, for which you will want to each have their own output path.
I resolved the issue by instead using MSBuild to compile, and setting the OutDir property on each build.
e.g. MSBuild projectB.csproj /p:OutDir=C:\AppBOutput\
This will put the output for project B, its dependent projects (prj A), and prj As copy local dependencies all into the C:\AppBOutput\ directory.
Why it Works
When building the project in Visual Studio, both prj A and prj B have their own output directory, e.g. prjA\bin\debug and prjB\bin\debug. The GAC-stored assembly set to copylocal will be included in the output directory of the project that directly references it (prjA). But it will not be copied to the output directory of the project referencing that project (prjB). That's just how the project reference copying works. Dig into the MSBuild targets and I'm sure the underlying reason could be found (sorry, not doing it myself).
What the /p:OutDir=C:\AppBOutput\ MSBuild parameter does, is set the output directory of all projects to be the same. By doing this, you side-step the MSBuild behaviour of how it copies project-to-project reference outputs. Instead of relying on MSBuild to copy some of the content in prjA\bin\debug to prjB\bin\debug, you just force all projects to output to the same directory.

Compiling and deploying assemblies that are used as references for other projects

Okay so here is my situation:
Project A is in solution A, lets call it's output a.dll.
Project B is in solution B, lets call it's output b.exe.
Project B references a.dll
Both solutions are under source code control in different repositories.
My question is: how can i assure that Project A's output gets redirected to project B's "External references" folder, overriding the previous version of a.dll, regardless of what the local developers path structure looks like, is there a way to do this? alternatively could solution A, invoke the build of solution B and then copy it's output locally?
To be brief, automating builds accross solutions without a 'common directory structure' is possible through the use of:
commandline parameters
environment variables
I would encourage you however to consider the "Convention over Configuration" mantra and think up a convention about the relative positions of solutions A and B.
Furthermore it's possible to build projects and solutions using the MSBuild task. The binaries can be copied to your "External references" folder using the Copy task.