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.
Related
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'm trying to build my C# (WPF) project, which I originally generated in Visual Studio 2017 in VSCode. If I open a command prompt and build the project with C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe .\[Name]\[Name].csproj /t:Rebuild /p:Configuration=Debug
the build succeeds and the program runs as expected, but with the following message (not a warning nor an error):
Project file contains ToolsVersion="15.0". This toolset may be unknown or missing, in which case you may be able to resolve this by installing the appropriate version of MSBuild, or the build may have been forced to a particular ToolsVersion for policy reasons. Treating the project as if it had ToolsVersion="4.0".
But when I try to run and build in VSCode (Start with Debugging (F5)), the build fails. Also, VSCode shows every XAML-Element I referenced in code as undefined:
(The name '[Button/Label/TextBox/etc.]' does not exist in the current context [Name]
What do I need to define in the tasks.json and launch.json to make VSCode build my project?
The C# support in VS Code is optimized for cross-platform .NET Core development. WPF is neither cross-platform nor .NET Core and VS Code does not support debugging WPF applications. Due to this focus, many of the standard C# project types are not recognized by VS Code: https://code.visualstudio.com/docs/languages/csharp.
If you want the best possible experience when creating WPF applications, you should use Visual Studio.
I don't think that VSCode supports WPF since it focusses on projects built with .NET Core and Mono. WPF is not supported in .NET Core
I'm trying to build a C# UWP on Jenkins, however I'm getting the following error:
XamlCompiler error WMC1006: Cannot resolve Assembly or Windows Metadata file 'System.Runtime.dll'
Build tools 2015 and VS2015 are both installed on the Jenkins server, and the build script is targeting version 14 of MSbuild
A clean source code tree straight out of version control for a UWP app needs NuGet to run to find dependencies specified in the project.json files.
As a dev, this is something Visual Studio 2015 normally does for you.
On a build server, you will need to run the command-line NuGet 3.x executable so that all the dependencies are pulled down on your build machine before your build runs (MSBuild part).
Go to http://dist.nuget.org/index.html to get hold of the command-line NuGet.exe.
The command will have the form of nuget.exe restore [MyApp.sln].
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.
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.