Best way to handle multiple configuration matrix with rake? - build-process

I have an application that can be built in one of 2 configurations (Company1 or Company2) and in debug or release mode.
Company1 Release
All builds done with the Release compiler flag
Build and output core dll files to build directory
Build and output Company1Plugin.dll to build directory
Copy tools\templates\log4net.config to build directory
Copy tools\templates\Company1.MyApp.exe.config to build directory
Company1 Debug
All builds done with the Debug compiler flag
Build and output core dll files to build directory
Build and output Company1Plugin.dll to build directory
Build and output MyApp.Debug.dll to build directory
Copy tools\Growl\log4net.GrowlAppender to build directory
Copy tools\templates\debug.log4net.config to build directory
Copy tools\templates\debug.Company1.MyApp.exe.config to build directory
Company2 Release
All builds done with the Release compiler flag
Build and output core dll files to build directory
Build and output Company2Plugin.dll to build directory
Build and output PrintingUtility.dll to build directory
Copy tools\templates\log4net.config to build directory
Copy tools\templates\Company2.MyApp.exe.config to build directory
Company2 Debug
All builds done with the Debug compiler flag
Build and output core dll files to build directory
Build and output Company2Plugin.dll to build directory
Build and output PrintingUtility.dll to build directory
Build and output MyApp.Debug.dll to build directory
Copy tools\Growl\log4net.GrowlAppender to build directory
Copy tools\templates\debug.log4net.config to build directory
Copy tools\templates\debug.Company2.MyApp.exe.config to build directory
I'm at a bit of a loss how to best model this matrix of dependencies in my rake file.
I would like to be able to simply do:
rake company1 #(release is the default)
rake company1 release
rake company2 debug
but cant quite figure out how to do this.
Obviously I have a build_and_output_core task that everything depends on, but then what? I can have the company1 and company2 tasks simply set some variables as to what should be done but then what triggers the actual copy activity?
I'm just getting started with both rake and ruby so any general advice is appreciated.

I would make two namespaces with the same code in, like the following code. If the number of companies grows beyond 10 companies I would start consider not making namespaces.
def do_stuff(company, mode)
# do stuff
end
namespace :company1 do
task :build_debug do
do_stuff("company1", :debug)
end
task :build_release do
do_stuff("company1", :release)
end
task :bd => :build_debug
task :br => :build_release
end #namespace company1
namespace :company2 do
task :build_debug do
do_stuff("company2", :debug)
end
task :build_release do
do_stuff("company2", :release)
end
task :bd => :build_debug
task :br => :build_release
end #namespace company2

Related

Azure devops VSBuild , Argument Outputpath

Hello I need to upload to Artifact the results of the VSBuild of the Solution but I can not use OutPutpath I get an error that the solution can not copy to certain files.
If I do not put an outputpath in the argument everything works fine, but I do not know what is the place of the VSBuild results to upload them to Artifact.
When using the VSBuild task to build a solution, normally the build artifact should be output into the directory of each project in the solution. So, the output path you set on the VSBuild task should be a relative path to each project directory.
You can follow the steps below to set up your pipeline:
On the VSBuild task, set the output path like as this.
-p:OutputPath={the relative path}
After the build, use the Copy files task to copy the artifact files form the output path to the directory $(build.artifactstagingdirectory).
Then use the Publish Pipeline Artifacts task to publish the artifact files from the directory $(build.artifactstagingdirectory).
The above are the most common steps to build projects and publish build artifacts in the build pipelines.

What to copy for a .Net Core console application publish?

I have an incredibly simple .NET core console application that I'd like to publish into a self contained executable. My application uses an the Microsoft.Extensions.Configuration.Json package so I can use an appsettings.json file.
From the command line, in the .csproj folder, I run
dotnet publish --self-contained true -r win-x64
. Inside my Debug folder, I see a netcoreapp2.1 folder and then the win-x64 folder. Inside that folder, I see the following:
publish -> folder
myapp.deps.json
myapp.dll
myapp.exe
myapp.pdb
myapp.runtimeconfig.dev.json
myapp.runtimeconfig.json
appsettings.json
hostfxr.dll
hostpolicy.dll
Am I supposed to copy just the files from this directory or do i have to copy the entire publish folder along with the files to my destination on a Windows Server? Or did I miss a switch to condense these items down further so movement from server to server is even simpler?
Copying just the files from the win-x64 directory was not enough. I needed to copy up the entire publish folder and run the application from that directory, otherwise error messages such as not being able to find a dependency would occur.

dotnet build project.csproj still searching directories

I am trying to build a single project using dotnet build when there are other project files in the directory tree.
According to the documentation,
Arguments
PROJECT
The project file to build. If a project file is not specified, MSBuild
searches the current working directory for a file that has a file
extension that ends in proj and uses that file.
Yet, when I run
dotnet build project.csproj -c Release
all directories are searched recursively, and it tries to build all the projects for which it finds .csproj files.
In my case, there is project.csproj in the root directory. Five directory levels down, there are three other .csproj files. Here's what the files look like, names changed:
./project.csproj
./scriptlibrary/Projects/project1/dir1/dir2/project2.csproj
./scriptlibrary/Projects/project1/dir1/dir3/project3.csproj
./scriptlibrary/Projects/project1/dir1/dir4/project4.csproj
When I run
dotnet build project.csproj -c Release
it finds the other .csproj files and tries to build them. project.csproj has no dependencies on the other projects.
This doesn't seem to be consistent with the documentation. What can I do to constrain the build to the single project I specify, on the command line?
Actually, there are two possible solutions to this problem:
Refactor your folder structure to exclude projects from subfolders. That will require new .sln for your projects.
./Main/project.csproj
./scriptlibrary/Projects/project1/dir1/dir2/project2.csproj
./scriptlibrary/Projects/project1/dir1/dir3/project3.csproj
./scriptlibrary/Projects/project1/dir1/dir4/project4.csproj
In case you cant do that you can exclude subfolders from the compilation by adding <DefaultItemExcludes> property item into project.csproj:
<PropertyGroup>
<DefaultItemExcludes>scriptlibrary\Projects\*</DefaultItemExcludes>
</PropertyGroup>
That will enforce compiler to exclude specified subfolders from compilation and other projects will not be compiled in scope of project.csproj

Visual Studio Team Services dotnet publish

My build completes with no errors, but it creates a randomly named zip file (s.zip) for the release step.
After the release step, I end up with that s.zip in inetpub/wwwroot/admin-tool/ folder. I'm almost there, but I want it to unzip and dump all the contents in here. This should be automatic, shouldn't it?
My dotnet publish looks like this:
and cause this to run, which is how I get the s.zip:
C:\Program Files\dotnet\dotnet.exe publish C:\agent\_work\3\s\Angular.AdminTool.csproj -c release --output C:\agent\_work\3\a\s
If I try to edit the -o argument and make it -o $(Build.ArtifactStagingDirectory)/admin-tool I will just end up with C:\agent\_work\3\a\admin-tool\s.zip
Is getting the name of my zip to be the same as the name of my web-site (admin-tool) the key to getting the zip to automatically extract in the release step?
In case it help others, I used the simple command line tools rather than the pre-canned "dotnet core" ones:
and for the Archive files task, be sure to include a hard-coded name for the zip to be used in the build process:
And for the release, in the "Deploy IIS App" task, be sure to include the full path for the zip file:
I also ran into this issue but solved it another way.
In my case I have a single project to build and deploy.
The $(Parameters.RestoreBuildProjects) value is set to a single project
MyProjectFolder/MyProject.csproj.
In the .Net Core Publish task, this value is used in the Path to Project(s) field.
Then I tick both the boxes for
I saved and queued this pipeline.
The zip file created seems to be derived from the name of the folder
so I ended up with a zip file in the artifact staging directory with the name of the project. Then the Publish Artifact task placed this zip file into the Artifact that is named in that task.

Unable to customise the build directory for Qt Creator/qmake

I've got problem trying to specify the build directory (the directory that is to store all the files prior to copying them to the DESTDIR path).
I've got the following values in my .pro file:
DESTDIR = E:/Development/project/build/core/debug
OUT_PWD = E:/Development/project/build/core/debug
OBJECTS_DIR = $$DESTDIR/.obj
MOC_DIR = $$DESTDIR/.moc
RCC_DIR = $$DESTDIR/.qrc
UI_DIR = $$DESTDIR/.ui
Now, all the files eventually end up in that location, however during build, the compiler is always using the "E:/Development/build/MinGW_32bit-Debug/src/core" folder (note the missing project path). This is annoying, because I want to use the /Project/build directory as this location (which is not tracked in my git repo).
Ideally, I'd like this path to be: E:\Development\project\build\src\core\debug.
The reason I want to do this is that the build process has the same location to include the compiled libs from (it's a subdirs project).
I've had a look in the Tools > Options > Build & Run > General settings, and the default build directory is: build/build-%{CurrentProject:Name}-%{CurrentKit:FileSystemName}-%{CurrentBuild:Name}
I've had a look in my project.pro.user file, and found the following line:
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">E:/Development/build/MinGW_32bit-Debug</value>
However I'm unable to change this value. If I edit this line in the file directly, as soon as I open Qt Creator again, the change has reverted back.
Is this a Qt Creator thing, or is it a qmake thing? Would I better off using a different build system such as CMake?
The build directory is "specified" by starting qmake or cmake in the build directory. There's no point to setting it in the .pro file itself.
Qt Creator stores the build directories for a project in the .user file. Any changes made to this file outside of Qt Creator, while the project is open in the Creator, will be lost. Creator loads the file when opening the project, or creates a new one if it doesn't exist.
When the Creator starts the build by invoking qmake or cmake, it starts that process in the build directory. That's also how you should be building the project manually from the command line.
Finally, it makes very little sense to override the destinations of the intermediate build results. They are somewhere within the build directory, and that's all that matters. You're not using these files directly for anything anyway.
The customary way to build a qmake project:
mkdir project-build
cd project-build
qmake ~/project-src
make -j
The build folder should not be within the source tree!
I've recently started keeping them in $TEMP / %TEMP%: manually purging the stale builds of all sort of test projects got old after a while :)

Resources