I have a solution with 4 projects:
a C++ .lib "A"
a C++ .dll (based on SWIG generated wrapper) "AWrapper"
a C# .dll (based on SWIG generated wrapper) "ASharp"
a C# Unit Test project (default, yet I can port it to NUnit) "ASharpTests"
Looking at general documentation, C# Travis CI docs and C++ docs cant get how to solve such multylingual project problem.
I can create CMake project for C++ library and wraper. But what shall I do next, how to solve next problems:
How to compile only selected projects from VS solution?
How to mix multiple lenguages, what one shall write into Travis configuration (2 C++ projects, 2 C# projects, to run tests a .so build from C++ code must be at the same folder as C# tests)?
CI Build Tool - MSBuild
If you are using Visual Studio to build your C++/C#/VB/other solutions, you should use MSBuild as the CI build tool.
See: https://msdn.microsoft.com/en-us/library/dd393574.aspx
MSBuild may be used to build project files in Visual Studio (.csproj,.vbproj, vcxproj, and others). However, it is not recommended. Instead, MSBuild should build Visual Studio solutions (.sln) directly. The main reason is that this way the Visual Studio IDE (used by developers) and MSBuild command line (used by CI system) build a solution exactly the same way. Secondly, changing configuration will be in one and only one place when changing projects by using the Configuration Manager in IDE.
MSBuild XML script example:
<Target Name="BUILD_SOLUTION">
<MSBuild Projects="$(SOLUTION_NAME).sln" Properties="Configuration=Release;Platform=Win32"/>
<MSBuild Projects="$(SOLUTION_NAME).sln" Properties="Configuration=Release;Platform=x64"/>
</Target>
Remember to Set Project Dependencies and Check Project Build Order. For examples,
Common libraries built before final EXE projects;
Unit Test projects built after corresponding production projects.
MSBuild Properties="Configuration=x;Platform=y" maps to Configuration Manager. Remember to set all Configuration and Platform combinations:
Select (enable checkbox) Build for each project context if needed;
Deploy column is not used.
I suggest you to set up your Travis configuration as C# (ie. language: csharp). With this, your project will be integrated in a C# environment with all the necessary tools. For your two C++ projects, it should not be too difficult to install mandatory tools. It as simple as a sudo apt-get install g++ cmake (and other required packages). You have to do this in the install section of your .travis file.
Note: The exact manner to install missing packages may vary depending if you use the docker-based Travis infrastructure or the legacy one.
Then, in the script section, you can build your c++ projects with cmake and then build your C# projects.
Related
I'm trying to build a docker image to setup CI/CD for a project of my organization.
The project is mostly Windows C++ (MFC), but has some components in C#.
Storically the projects were all managed by hand but I'm in the process of migrating to CMake and automate the build process.
Locally everything works fine but when building on the CI/CD server, CMake says that No CMAKE_CSharp_COMPILER could be found.
The docker image I'm building is based on mcr.microsoft.com/windows/servercore:ltsc2019 and I installed, using the Visual Studio Build Tools installer, the following workloads:
Microsoft.VisualStudio.Workload.MSBuildTools
Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools
Microsoft.VisualStudio.Workload.VCTools
Microsoft.VisualStudio.Component.Windows10SDK.17763
I can provide the full Dockerfile if necessary.
Anyway, testing the built image I can find both msbuild and csc compilers, CMake can't.
Any idea on what could be the problem?
Looks like I was missing a Visual Studio component, specifically Microsoft.Net.Component.4.TargetingPack.
To detect the correct C# compiler, CMake compiles a little source code. This compilation targets .NET Framework v4, which I was missing.
Using CMake 3.13 to generate Visual Studio 2017 C++ project will produce a solution that includes "INSTALL" and "ZERO_CHECK" and "ALL_BUILD" projects. All these projects use Configuration Type "Utility" which does not compile code but shall "Displays utility toolset (MIDL, custom build, prebuild, postbuild events)".
Does Visual Studio 2017 provide a similar project type for a pure C# solution? In this scenario the developers do not have C++ package installed on their VS2017.
I am compiling a solution using Visual Studio 2019. This solution has two projects, we can call them Common and Program. Program depends on Common and Common depends on the NuGet packages LibVLCSharp, LibVLCSharp.WPF and VideoLAN.LibVLC.Windows.
If I clean and then build Program, everything is fine: the dlls are correctly copied in bin/Debug or bin/Release. But if I make any change to Program and compile it without cleaning it, the dlls relative to VLC disappear.
What can be the reason for the dlls to disappear?
In the visual studio UI I do not see the commands it is running when I compile the project. How can I debug it?
It seems that you are referencing VideoLAN.LibVLC.Windows on your Common project rather than in your Program project. This is not a scenario that we support.
I wrote this explanation about which project you should install LibVLC in.
In short, you should install the LibVLC package only into your application project, because we insert a build step that copies the files to the Output Folder of your project.
If you reference the LibVLC project in the Common project, there is no way we can copy the files to the Program project, because it is not known by MSBuild. You would then have to tell MSBuild to copy those files from Common/bin/... to Project/bin/..., but trust me, you don't want to mess with MSBuild.
EDIT: That doesn't mean that you can't use LibVLCSharp in your Common project. You can reference the LibVLCSharp packages in your Common project, because it only depends on VideoLAN.LibVLC.Windows at runtime.
I am working on a project that requires me to build a .dll file in .NET framework 4.x
I know this would be super easy if I were to use Visial Studio. But I have set my mind on using VS Code as my IDE.
In theory Visual Studio "only" automates the creation of all sorts of metadata and references. So I figured it should be possible to do these things manually. Correct?
Can anybody direct me to where I can find how to do that?
I am working on Windows 10.
Because Code isn't adept at managing a project file (.csproj) - nor should anyone have to - you can actually use the dotnet.exe CLI to create the project and target .NET Framework instead. The only requirement is that .NET Core SDK needs to be installed, even if you use MSBuild because the new SDK-style project requires different targets.
Run: dotnet new classlib -o MyLibrary
Run: code MyLibrary
Open MyLibrary.csproj in Code
Change the line <TargetFramework>v4.5</TargetFramework>
Now you can run dotnet build or msbuild build, and even set up build and test tasks in Code. By default, Ctrl+Alt+B will run a build task, or prompt to create one from a template if none exist yet.
Now you can simply add files without modifying the .csproj file. I participate in many OSS projects that use technique and can easily switch between VS, Code, or even non-IDEs like vim.
It would require from you to type a lot of code and files that are otherwise automatically scaffold (generated) when you create a new project in Visual Studio. Even though VS Code is supportive for .NET framework coding (with the C# plugin), I would advice you to use Visual Studio (the community version would suffice). It has much better support for any .NET framework development.
I read the following both articticles about the using of portable class library(PCL) in application design:
http://www.dotnetcurry.com/showarticle.aspx?ID=843
and
http://blogs.msdn.com/b/dsplaisted/archive/2012/08/27/how-to-make-portable-class-libraries-work-for-you.aspx
I created an PCL and a unit test project to test the PCL. I build everything with my visual studio 2012 and it works great, i was also able to start my application using this PCL.
I use a TFS for source controll and nightly tests.
If i try to build the the unit test project or my apllication via TFS i retrieve two errors:
CA0055 : * Could not load file: 'C:...\MyPCL.dll'.
CA0052 : No targets were selected.
The PCL use .Net Framework 4.5 and .Net for Windows Store apps as targets and all projects which are no PCL are configured to use .Net Framework 4.5. I does not use any other reference as the default ".Net Protable Subset" reference.
If i check the build server there is a compiled and working version of my PCL.
If i disable the code analysis while building there are no errors and all unit test works fine.
But it is no solution for me to disbale the code analysis. So has anybody an idea why it crashed and how to get it working with code analyse?
I ran into the same problem after renaming the project. Check the AssemblyInfo.cs file, make sure the assemblyTitle is correct. Better to have it same as the project name, and is not conflicting with any other projects
Is your local build working fine when code analysis is enabled in Visual Studio?
If yes then one of the possible reason for this issue can be build output path in TFS Build. In local builds, output files are generated in bin directory of respective projects where as in TFS Build all the project output files are copied in binaries directory.