I have a solution that includes a number of projects that are plugins, ie. these projects are not referenced in the main project.
In order to copy the files on build I have a post-build event that simply copies the files as in:
xcopy "$(SolutionDir)bin\Debug\net5.0\MyApp.Plugin.*.dll" "$(TargetDir)" /Y
The above is for each and every plugin project.
These type of projects are increasing and it is getting quite messy on build and publish. So I was thinking of creating a dummy project that references all these projects and then reference this dummy project in the main app project.
With the above approach I can have all files in my bin folder so I can test locally. But obviously I don't need the dummy project on publish.
Is there a better solution on how to reference projects and exclude projects on publish?
Related
I have a CS project that depends on some archive files and I have created MSBuild targets to build them. I cannot, however, get MSBuild to build these targets if project's files are up to date.
I have tried referencing the archive targets in the following places:
The project's before and after build targets
The project's InitialTarget and DefaultTarget attributes
In a separate targets file, which I tried to add as a project reference to my project. I'm not sure I used the item correctly though.
When I build, Visual Studio tells me that my project is up to date and does nothing. How can I make it consider my other targets as dependencies?
It seems that you build the project in VS IDE. VS IDE has a up-to-date check, if the project's output files are up-to-date with respect to their corresponding input files, it won't start build process.
I cannot, however, get MSBuild to build these targets if project's
files are up to date.
Check this thread, if the input source files and output assemblies are corresponding up-to-date, VS won't really build and won't call your custom targets.
And according to your description, what you want is to run your target no matter if project file is up-to-date, I'm not sure what you mean make it consider my other targets as dependencies.What you really want is to run the custom targets anyway, if so, you can build the project by command-line or try rebuild instead of build button in VS. If I misunderstand anything, please feel free to let me know.
I'm working on a C# application which requires integrating with another company's software. I have isolated all of the code that is tightly coupled to this integration in a single C# project. This way, if the company changes something with their integration, I only have to change code in this one project. The project is a non-executable class library (Project A).
One weird/annoying part of this integration though is that it involves manually copying compiled .dll files from the company's SDK into the bin directory of the project after the project is built. I can't just use a nuget package or something similar. While annoying, I have automated it with a post-build script and it works well enough for that specific project.
I then reference this project/class library from an executable class library, such as a .NET Framework Console project (Project B).
Now I have a problem:
Build Project A
Runs post-build script XCopy C:\CompanyIntegration\Autofac.dll "${TargetDir}".
Compiles without any issues.
Build Project B
Compiles Project A, copies .dlls from Project A bin to Project B bin.
The copied Autofac.dll from Project A overwrites one installed via a nuget package.
The build throws an exception because it expected a different Autofac.dll.
How can I tell the build process to differentiate between these two different Autofac versions/dlls?
Why are the company integration .dll files copied from the bin folder of Project A to the bin folder of Project B in the first place?
Is it possible to make Visual Studio to copy all dependencies of referenced projects into the output path?
Example
In the Solution, Project A (Library, .NET Standard) defines some functions and is dependent on Library L1 (via NuGet) and Library L2 (local .dll, referenced and copied to project)
Project B (Console Application) references Project A.
When building B, The output folder contains all direct dependencies of B and A.dll. L1 and L2 are not available in the output. Therefore, the program does not work correctly.
How can I force VS to copy also L1 and L2 to the output of B?
The only way I found so far is packing A as NuGet, but this seems to be unnecessary overhead and uncomfortable. I think I am just forgetting something everyone else seems to know...
Edit (clearifying Example)
My solutions consists of two projects.
Project MongoWrapper
.NET Standard 2.0 class Library
depends on NuGet MongoDB.Driver package
Actually uses this dependency (no zombie dependency)
Project ConsoleUser
.Net Framework 4.6.1 Console Application
References MongoWrapper project
Actually uses MongoWrapper
Observation
When debugging the ConsoleUser application, it compiles and starts. During runtime, when it calls a method in the MongoWrapper which uses the MongoDB.Driver, the application crashes, as the MongoDB.Driver dependency was not copied into the output folder of the ConsoleUser.
How to fix this?
The problem was introduced by the usage of .Net Standard library and a .Net Framework application.
TLDR
Open the .csproj file of the .Net Framework project with a text editor. Inside the first PropertyGroup add the line
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
Save the file, reopen Solution in Visual Studio and perform Clean & Build
Dependencies in different project file versions
.Net Framework projects use an old version of the .csproj project files. References/Dependencies are stored in the additional packages.configfile. By default, building a .Net Framework project makes the system to search for a packages.config file in the referenced projects. If no such file is found, the build task treats the referenced project as having no dependencies. Therefore, in the example, the MongoDB.Driver library is not added.
By adding the proposed line in the .csproj project file, the build task searches the project file of the referenced project for dependencies, where they are stored in .Net Standard project files.
.Net Core projects by default search for the newer project file structure.
The default behavior for new projects can be set in the Options -> NuGet -> General -> Package Management
Is it possible to make Visual Studio to copy all dependencies of referenced projects into the output path?
Yes.
This is what publishing the application does - it prepares the application for deployment. When you publish, it will include all of the dependencies that the application requires to run in the output.
Use the Publish tool to deploy to a local folder. The exact options available depend on your app type. In Solution Explorer, right-click your project and choose Publish, and then choose Folder. For more information, see Deploy to a local folder.
Tutorial: Publish your Hello World application with Visual Studio 2017
Also see: .NET Core application deployment.
I wonder where dll files are stored in Visual Studio and whether its the best way to keep them there or consolidate elsewhere for the following cases:
1) My solution includes a c# library project which other projects in the same solution reference to. My understanding is that the library project stores the dll in its own directory /bin folder. So do I need to establish the reference to that library by pointing to the dll in that external folder? Problem is that this dll should later be shipped with the projects referencing to the dll file. Will the projects who reference to the dll file create a copy of the dll in their own project /bin folders or how does it work?
2) where should I copy external libraries to that are referenced by projects I like to ship in compiled fashion? Should a dll be copies and referenced to into each project's bin folder that utilizes such external library?
I am a bit confused by how going practice is and could not find straightforward answers in other posts here.
Thanks
If you can set two solutions one for your dll referenced and another for your project that reference them after
create a dependencies folder where you will set all binaries that are dll you need
set path to this dependencies folder on all your projects that will create dll you want to reference
set build order on your solution to first build your dll and after build your project that reference your dll
when you deploy it, make sure that you create dependencies folder
For your information, your application first see on GAC folder (windows\assembly), after see on your current path, and after use PATH environment variable.
I have a project template that builds a windows forms application. The windows forms application must have a reference to an assembly that I have also built.
When I package the project template in a VSIX (or just build it and put it in the templates folder), the project does not have a reference to the assembly. How can I package the assembly in the VSIX? Ideally I'd like to install it in the GAC but I know this is not possible - is there any way for me to create a folder in the project with a name like 'Dependencies' and include my assembly there? And how can I do this?
Thanks in advance!
OK I have solved this.
The way I do it is create a project I will use as a baseline for the template. Then I include the DLLS in the actual project files, in a Folder named 'Dependencies'. These have their build action set to 'None'. After this, I add references (by path) to the binaries in the Dependencies folder. Now when I export the project as a template everything works fine.