Visual Studio Online Build Fails on Dependent Project NuGet References - msbuild

I am using Visual Studio Online for my repo and build. Here is my TFS hierarchy.
<ClassLibraries>
│
├───<Solution 1>
│ └───Build.Proj
│ └───.NuGet
│ └───NuGet.exe
│ └───NuGet.Config
│ └───NuGet.Targets
│ └───<Project 1> // Common Code
│ └───Project1.csproj
│ └───<Project 2> // Common Code Unit Test
│ └───Project2.csproj
│
├───<Solution 2>
│ └───Build.Proj
│ └───.NuGet
│ └───NuGet.exe
│ └───NuGet.Config
│ └───NuGet.Targets
│ └───<Project 3>
│ └───Project1.csproj
│ └───<Project 4>
│ └───Project2.csproj
I have a build definition for Solution 1 which builds succesfully, restoring the NuGet packages as required without issue.
The Solution 2.sln file includes Project 1 from Solution 1 as a dependency, as both Project 3 and Project 4 have code dependencies on it (Solution 1 is my common code solution, which is included in just about everything).
The build definition for Solution 2 fails because it cannot find the NuGet dependencies for Project 1. I guess the RestorePackages target in the Build.Proj is ignoring the dependent project.
<Target Name="RestorePackages">
<Exec Command="$(MSBuildThisFileDirectory).NuGet\NuGet.exe restore %(Solution.Identity)" />
</Target>
I can't fathom out why. If I execute "msbuild build.proj" locally on Solution 2 then it cleans and builds all projects succesfully.

I have worked out that my build.proj file needs to reference directly Solution 1 in this example:
<ItemGroup>
<Solution Include="$(MSBuildThisFileDirectory)*.sln" />
<Solution Include="$(MSBuildThisFileDirectory)..\Solution1\*.sln" />
</ItemGroup>
This then causes MSBuild to go through the NuGet package restore for the dependent project. Problem solved. Sort of..
After I had deleted all my local code and performed a Get Latest from the repo, I realised that VS2013 exhibits the behaviour I originally saw. So I need now to work out how to make the IDE build in the same way as the Build.Proj file I am using for VSO and msbuild executed from the command line.

Related

Summary HTML Report not generated when path is specified in terms of classpath in Karate

I am trying to run some test cases using Karate v1.2.0 (with Junit5). Everything is working well, except for a minor discrepancy that seems to be occurring during report generation. The project folder structure is something like this
my-project/
├── src/
│ └── test/
│ └── java/
│ ├── ronan/
│ │ ├── api/
│ │ │ ├── ApiTest.java
│ │ │ ├── feature-1.feature
│ │ │ └── feature-2.feature
│ │ └── util/
│ │ └── SomeUtil.java
│ ├── karate-config.js
│ └── logback-test.xml
└── build.gradle
When my ApiTest.java specifies the path by individual feature file names, the individual feature HTML reports and the summary HTML report are generated.
#Karate.Test
Karate testAPI() {
// Generates individual HTML reports as well as the summary HTML report
return Karate.run("feature-1", "feature-2")
.outputJunitXml(true)
.relativeTo(getClass());
}
However, when I specify the path using classpath:, only the individual feature HTML reports are generated and not the summary report.
#Karate.Test
Karate testAPI() {
// Generates ONLY individual reports
return Karate.run("classpath:ronan/api")
.outputJunitXml(true)
.relativeTo(getClass());
}
The test task is configured in build.gradle as below
test {
useJUnitPlatform()
systemProperty "karate.options", System.properties.getProperty("karate.options")
systemProperty "karate.env", System.properties.getProperty("karate.env")
outputs.upToDateWhen { false }
}
I wasn't able to find any relevant documentation or SO answers related to the same, so I'm not sure if this is expected and if I'm doing something wrong or if it's an issue with report generation.
Any help on this would be greatly appreciated. Thanks!
For CI, please use the Runner API, and only then can you run tests in parallel. The JUnit helpers are just for IDE dev-loop convenience.
Please read this for details: https://stackoverflow.com/a/65578167/143475
Now if you still see issues with the Runner, then open an issue with a way to replicate. Meanwhile you are welcome to contribute code to fix the problem you describe in your question.

Fortran fpm Run Tests on Module in Parent Directory

I have written a module in fortran that I want to test using fortran-fpm and vegetables.
My directory structure looks like this:
my_repo/
├─ foo/
│ ├─ bar/
│ │ ├─ my_module.f90
│ │ ├─ test/
│ │ │ ├─ main.f90
│ │ │ ├─ my_module_test.f90
├─ fpm.toml
When I run fpm test, I get this error:
<ERROR>*cmd_run*:targets error:Unable to find source for module dependency: "my_module" used by "foo/bar/test/my_module_test.f90"
STOP 1
If I instead move my_module.f90 into the test directory, all the tests run fine. How do I point my_module_test.f90 to my_module.f90 without having my source code in the test directory?
I have tried:
Including:
[test-dependencies]
my_module = { path = "foo/bar/my_module.f90" }
in my fpm.toml file at the top of my repo as suggested in the documentation. It then prompts me to put another fpm.toml file at foo/bar/. When I do that, it still gives me the same error.
Using putting file: "foo/bar/my_module.f90 at the top of my_module_test.f90. As suggested here.
EDIT:
Note that my fpm.toml file looks like this:
name = "My_Project"
author = "NolantheNerd"
[install]
library = true
[library]
source-dir = "foo/bar"
include-dir = "foo/bar"
[build]
external-modules = "foo/bar"
link = "foo/bar/my_module.f90"
[dev-dependencies]
vegetables = { git = "https://gitlab.com/everythingfunctional/vegetables.git", tag = "v7.2.2" }
[[test]]
name = "TestsForMyModule"
source-dir = "foo/bar/test"
main = "main.f90"
link = "foo/bar/my_module.f90"
Many thanks to everythingfunctional, the creator of vegetables for his solution:
Your build section is incorrect, and actually unnecessary in your case. Try removing it and let us know how it goes.
Edit: just noticed as well that the link entry in your test section is incorrect and unnecessary as well.
See the thread here.

MSBuild: Copy files conditional output paths

I currently have a solution with the following project layout (simplified and condensed for this example)
src
├──2019
| └── Project.2019
| └── Input
| └── 1.txt
└──2020
└── Project.2020
└── Input
└── 1.txt
And I would like to copy all the input files to the following hierarchy
Input
├──2019
| └── 1.txt
└──2020
└── 1.txt
With [System.IO.Directory]::GetDirectories I am able to match the directories I want, but I'm not sure how to extract the year, and set DestinationFolder correctly using the Copy task
Does Project.2019 and Project.2020 include projects?
I have made the assumption that it does, following this structure:
directory.build.props
│
└───src
│ CopyFiles.sln
│
├───2019
│ └───Project.2019
│ │ Program.cs
│ │ Project.2019.csproj
│ │
│ └───input
│ 1.txt
│ 2.txt
│
└───2020
└───Project.2020
│ Program.cs
│ Project.2020.csproj
│
└───input
1.txt
2.txt
Having a project file in each of those folders, allows us to execute a custom build target, under the context of each project. This grants a simple way of building the list of files (includes) and allows us to go up a folder from the MSBuildProjectDirectory to get the year.
The final output path for the input files (InputOutputPath), assumes the existance of OutputRootPath and OutputPath is used to overwrite the default msbuild folders. I typically do this to have all output in \output. But you can customize these as you wish.
It also expects each project that needs files copied to have CopyInputFiles specified to true. This can also be done using a condition, in case you want it to always copy files if there are any in project\input*.txt
<PropertyGroup>
<CopyInputFiles>true</CopyInputFiles>
</PropertyGroup>
directory.build.props:
<Target Name="CopyFiles" Condition="'$(CopyInputFiles)' == 'true'" >
<ItemGroup>
<InputFiles Include="$(MSBuildProjectDirectory)\input\*.txt" />
</ItemGroup>
<PropertyGroup>
<Year>$([System.IO.Directory]::GetParent($(MSBuildProjectDirectory)).Name)</Year>
<InputOutputPath>$(OutputRootPath)\$(Configuration)\Input\$(Year)\</InputOutputPath>
</PropertyGroup>
<Copy SourceFiles="#(InputFiles)" DestinationFolder="$(InputOutputPath)" />
</Target>
Example output:
PS e:\repos\CopyFiles> msbuild .\src\CopyFiles.sln /t:copyfiles
Microsoft (R) Build Engine version 16.8.2+25e4d540b for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
Build started 12/6/2020 12:56:07 PM.
Project "E:\repos\CopyFiles\src\CopyFiles.sln" on node 1 (copyfiles target(s)).
ValidateSolutionConfiguration:
Building solution configuration "Debug|Any CPU".
Project "E:\repos\CopyFiles\src\CopyFiles.sln" (1) is building "E:\repos\CopyFiles\src\2019\Project.2019\Project.2019.csproj" (2) on node 1 (copyfiles target(s)).
CopyFiles:
Creating directory "E:\repos\CopyFiles\Drops\Debug\Input\2019".
Creating directory "E:\repos\CopyFiles\Drops\Debug\Input\2019".
Copying file from "E:\repos\CopyFiles\src\2019\Project.2019\input\1.txt" to "E:\repos\CopyFiles\Drops\Debug\Input\2019\1.txt".
Copying file from "E:\repos\CopyFiles\src\2019\Project.2019\input\2.txt" to "E:\repos\CopyFiles\Drops\Debug\Input\2019\2.txt".
Done Building Project "E:\repos\CopyFiles\src\2019\Project.2019\Project.2019.csproj" (copyfiles target(s)).
Project "E:\repos\CopyFiles\src\CopyFiles.sln" (1) is building "E:\repos\CopyFiles\src\2020\Project.2020\Project.2020.csproj" (3) on node 1 (copyfiles target(s)).
CopyFiles:
Creating directory "E:\repos\CopyFiles\Drops\Debug\Input\2020".
Copying file from "E:\repos\CopyFiles\src\2020\Project.2020\input\1.txt" to "E:\repos\CopyFiles\Drops\Debug\Input\2020\1.txt".
Creating directory "E:\repos\CopyFiles\Drops\Debug\Input\2020".
Copying file from "E:\repos\CopyFiles\src\2020\Project.2020\input\2.txt" to "E:\repos\CopyFiles\Drops\Debug\Input\2020\2.txt".
Done Building Project "E:\repos\CopyFiles\src\2020\Project.2020\Project.2020.csproj" (copyfiles target(s)).
Done Building Project "E:\repos\CopyFiles\src\CopyFiles.sln" (copyfiles target(s)).
With the resulting structure:
Drops
└───Debug
├───AnyCPU
│ ├───Project.2019
│ │ └───netcoreapp3.1
│ └───Project.2020
│ └───netcoreapp3.1
└───Input
├───2019
│ 1.txt
│ 2.txt
│
└───2020
1.txt
2.txt
You can find a fully working example in: https://github.com/Kencdk/msbuild_copyfiles_example
You can hook it up to your build, by setting the target to execute after any other build target that is being executed in your projects.
eg:
<Target Name="CopyFiles" Condition="'$(CopyInputFiles)' == 'true'" AfterTargets="Build">

msbuild: build as to a appxbundle (AppxBundle=Always not working)

I have a shared Windows8.1 project with a Phone and Desktop project in it. I defined different configurations to build x86/x64 for desktop and ARM for phone.
msbuild works fine without error, but there is no final *.appxbundle file on the output folder (or anywhere else) although i set the parameter AppxBundle=Always.
my command looks like this:
msbuild myApp.sln /p:OutputPath=%OUTPATH%;Configuration=Phone;Platform=ARM;AppxBundle=Always;AppxBundlePlatforms=ARM
/t:Rebuild,Publish
The output is:
OUTPATH
├── ForBundle
│ └── AppxManifest.xml
├── AppxManifest.xml
├── App.WindowsPhone.build.appxrecipe
├── App.WindowsPhone_3.2.1_ARM.appx
├── App.WindowsPhone_3.2.1_scale-100.appx
├── App.WindowsPhone_3.2.1_scale-140.appx
├── App.WindowsPhone_3.2.1_scale-180.appx
├── resources.pri
└── SomeDependency.winmd
I tried to pack this folder with makeappx.exe bundle but this didn't work and I realized the folder looks a bit different to what is into a appxbundle.
Creating a appxbundle via VS GUI is no problem, but I would like to automate that step!
Thanks in advance!
There's a hint comment in Microsoft.AppXPackage.Targets:
When building on the command line or in TFS (determined by looking at the $(BuildingInsideVisualStudio) property), if build is
invoked on an
app package-producing project, the package for the project will be produced as part of building the project without specifying
any additional
flags or targets. This is control by an MSBuild property named GenerateAppxPackageOnBuild which is set to true by default.
If $(BuildingInsideVisualStudio) = false and $(GenerateAppxPackageOnBuild) = true, then build will also produce a
package.
true
FYI, the file has moved for VS 2022, new location isL
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VisualStudio\v17.0\AppxPackage

cmake find_path doesnot work on windows

on my first cmake project it looks like the find_path does not work on windows when im trying to reference package libcurl. im using cmake 2.8.12.2.
i took a look at FindCURL.cmake source code and tried below:
if(WIN32)
set(CMAKE_PREFIX_PATH
"${WIN32_LIBS_DIR}/libcurl"
"${WIN32_LIBS_DIR}/libcurl/include"
"${WIN32_LIBS_DIR}/libcurl/lib"
)
find_path(CURL_INCLUDE_DIR NAMES curl/curl.h) # this line is copied from the first line of FindCURL.cmake source
message("WIN32_LIBS_DIR: ${WIN32_LIBS_DIR}")
message("thu ${CURL_INCLUDE_DIR}")
and get the result of
WIN32_LIBS_DIR: ../../../lwqq_root/win32-dev
"thu CURL_INCLUdE_DIR_NOTFOUND",
by the way, the variable WIN32_LIBS_DIR is set to win32-dev which looks like below:
└─win32-dev
├─libcurl
│ ├─bin
│ ├─include
│ │ └─curl
│ │ └─curl.h
│ ├─lib
│ │ └─pkgconfig
│ └─samples
any idea why?
The modern way to use CURL is to use the imported targets created by FindCURL and to guide the search with CURL_ROOT, like so:
set(CURL_ROOT "${WIN32_LIBS_DIR}")
find_package(CURL REQUIRED)
add_executable(my_target main.cpp)
target_link_libraries(my_target PRIVATE CURL::libcurl)
See: https://cmake.org/cmake/help/latest/module/FindCURL.html
Your question does not include enough detail to reproduce your issue. Here is what I did to try:
cmake_minimum_required(VERSION 3.20)
project(test LANGUAGES NONE)
# Create the directory structure in the question:
file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/win32-dev/libcurl/bin")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/win32-dev/libcurl/include/curl")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/win32-dev/libcurl/lib/pkgconfig")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/win32-dev/libcurl/samples")
file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/win32-dev/libcurl/include/curl/curl.h" "")
# Set WIN32_LIBS_DIR to the root just created
set(WIN32_LIBS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/win32-dev")
# Your code:
set(
CMAKE_PREFIX_PATH
"${WIN32_LIBS_DIR}/libcurl"
"${WIN32_LIBS_DIR}/libcurl/include"
"${WIN32_LIBS_DIR}/libcurl/lib"
)
find_path(CURL_INCLUDE_DIR NAMES curl/curl.h)
message(STATUS "WIN32_LIBS_DIR: ${WIN32_LIBS_DIR}")
message(STATUS "CURL_INCLUDE_DIR ${CURL_INCLUDE_DIR}")
This was on Windows with CMake 3.20, but I am sure it would work going back. I tested this on Linux with every CMake version between 3.0 and 3.20 and it worked on all of them.
Here's what I see in the terminal:
D:\test>cmake -S . -B build
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19043.
-- WIN32_LIBS_DIR: D:/test/win32-dev
-- CURL_INCLUDE_DIR D:/test/win32-dev/libcurl/include
-- Configuring done
-- Generating done
-- Build files have been written to: D:/test/build
D:\test>tree /F win32-dev
Folder PATH listing for volume Sources
Volume serial number is 0000008F 943F:828D
D:\TEST\WIN32-DEV
└───libcurl
├───bin
├───include
│ └───curl
│ curl.h
│
├───lib
│ └───pkgconfig
└───samples
As you can see from the output, I have mirrored your directory layout exactly and the same settings of other variables has allowed find_path to succeed, even on Windows.