TFS Build using vstest.console.exe.config instead of app.config - tfs

For some time we had TFS2017 run our unit test (xUnit) in the build proces. Every test project has it own app.config file declaring some appSettings.
Our code is looking at those app settings like ConfigurationManager.AppSettings["someSetting"]
Recently, some developers upgraded from VS2015 to VS2017 (not sure if it is related), our test started to fail.
Turns out that the the appSettings where loaded from vstest.console.exe.configinstead of the app.config file included in the test project.
While we where able to add our settings to vstest.console.exe.config this is not our preferred solution, we would like to have the test using the app.config file again.
Any ideas on how to accomplish this? I have no idea what changed in the first place.

Make sure WorkingFolder is not changed. It should be relative to the folder containing the test.dll.
Also, you can try the <exec> task in MSBuild to run the console runner.
When running multiple assemblies, you can specify the configuration file for each assembly using ItemGroup metadata. The <xunit> task looks for metadata named ConfigFile on each item in your item group. Configuration files are ignored when AppDomains is set to false.

Related

Why is org-netbeans-modules-java-j2seproject-copylibstask.jar required failed ant build

When doing an ant build (thought jenkins) for a test project, I get the below error. As this test project will be deployed in tomcat why does the build require a netbeans specific module
Obviously I can add the jar file to a path in jenkins and then continue the build, but want to know why it needs a netbeans specific jar?
Is it because the project setup in Netbeans is wrong?
Thanks in advance.
Tony
======Error below here =========
var/lib/jenkins/workspace/DeployTest2/nbproject/build-impl.xml:797: The libs.CopyLibs.classpath property is not set up.
This property must point to
org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part
of NetBeans IDE installation and is usually located at
/java/ant/extra folder.
Either open the project in the IDE and make sure CopyLibs library
exists or setup the property manually. For example like this:
ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar

TFS NuGet Installer build step not working

I'm trying to configure an automated build of a project that has a NuGet package reference, but I'm not having any luck. (FYI I'm still pretty wet behind the ears with all of this, so please provide simple steps and/or configurations.)
Note: this isn't a duplicate of other similar questions, as I'm using a central package repository. Other similar questions make no mention of this important detail, so they should be assumed to not be relevant.
The build runs fine without the reference. I added Newtonsoft.Json and bound to it by including this simple construct:
Dim eHandling As Newtonsoft.Json.ConstructorHandling
eHandling = Newtonsoft.Json.ConstructorHandling.Default
I checked it in and the build started, but NuGet hadn't first copied the assembly to my application's bin folder. It did, however, copy it to here:
Restoring NuGet package Newtonsoft.Json.9.0.1.
Adding package 'Newtonsoft.Json.9.0.1' to folder 'C:\Agent\_work\1\s\packages'
Naturally the build failed, as it couldn't find the dependency.
It's worth noting that I'm using a central package repository on my dev machine:
<config>
<add key="repositoryPath" value="D:\Dev\Packages" />
</config>
I'd like to emulate this behavior on the server as well, e.g. C:\Packages\*\*.nupkg.
I tried using the standard %AppData%\NuGet\NuGet.config file, but the build ignores it. I tried the advice in this answer (using repositoryPath instead of packageSources as shown there), but that causes the server to hang until I restart the VSO Agent service. Thinking it might be a permissions issue, I reconfigured the agent to run under the user account associated with the %AppData% location of NuGet.config. Still no luck. No build.
How can I get NuGet to download and populate the central package repository on the server and then copy the appropriate dependencies to the application bin folder prior to running the build step?
EDIT 1
Update: Apparently something's working, as I now have a C:\Packages\Newtonsoft.Json.9.0.1 folder on the server. However, the assembly still isn't being copied to the application bin folder prior to build. Same result. Failed build.
EDIT 2
OK, I'm getting closer. I created a D: drive on the server and set the local repositoryPath value to D:\Dev\Packages, the same as it is on my dev machine. The build is still failing, but a quick look at the project XML reveals this:
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\..\Packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
How to deal with that relative path? That should fix it, yes?
EDIT 3
OK, that worked. I edited the project and changed HintPath to
D:\Dev\Packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll
I now have a successful build.
But this is going to get real tedious real fast. Surely I'm not going to have to do this for every single NuGet reference in every single project, past present and future... am I?
OK, got it.
As long as the repositoryPath folder on the server is the same number of levels deep as on our dev machine—in relation to the folder in which the Build Agent puts the project file—we can put it anywhere we want and retain the relative HintPath value in the project file.
For example, in my case I ended up setting the server location to C:\Agent\Build\Packages, to match the hierarchical location of the local Git repos on my dev machine:
D:\Dev\Packages
D:\Dev\Git\app.repo\App\App.vbproj
Works great.
EDIT
Just to clarify, the action of copying the assembly from the package folder to the application bin folder isn't a NuGet action. It's an MsBuild action (i.e. the CopyLocal setting in the project's assembly reference properties).
The reason it was failing was that MsBuild couldn't find the assembly to copy, according to its relative reference as specified in the project file.
So technically my question title is incorrect. The NuGet Installer step has been working fine all along.

Release manager for TFS 2013 app.config processing with token files

I seem to be getting a lot of pain with the processing of app.config and token files (we have this working with the older ".11" templates).
It looks like currently (using the ReleaseTfvcTemplate.12.xaml) this is running the tokenisation after the build.
While I can make the app.config / myapp.exe.config stuff work by deliberately copying the .token file into my output folder (so the recursive search finds it) this feels pretty horrid.
As a fix I'm tempted to move lines 182-230 to just before the RunMSBuild task on line 175 (creating a new sequence at that point)
Is this the correct approach or have I missed some documentation somewhere (or a later version of the template?)
Thanks guys... Anyway for future reference I did make the change.
However I had misunderstood the exact nature of the order things happen out of the box which is as follows:
Get the project out of source control
build with msbuild
Copy the .config.token file over the .config file. This is in the TFS template
As part of the deploy to a server then the token entries in the .config files are replaced. This is in the release manager template.
Tests are run in the msbuild binary output folders.
The problem is this doesn't really work if you're using an project type that uses app.config file as the msbuild process renames these output.exe.config during the msbuild stage so you need to create both an output.exe.config (marked as copy to output) and an output.exe.config.token so when the post deploy is the final output gets configured correctly. This also a problem if you want to tokenise some mstest dlls as these typically use an app.config as well. Basically this is a bit of a mess unless you are using web.config.
We worked our way around this by using the modification I suggested above (you need to create a sequence at line 175 and move lines 178-230 up into the sequence, this is GetBuildDirectory variable bits and the if statement) followed by adding an additional deployment stage which copies back onto the build server with the new tokenised files so the mstest can run against them.
So our new process looks like this:
Get the project out of source control
Copy the .config.token file over the .config file i.e app.config.token copied over app.config
build with msbuild (this means we end up with tokenised myapp.exe.config and mytests.dll.config)
As part of the deploy to a server then the token entries in the .config files are replaced. This is a release management step in the release template.
Deploy the tests back into a folder on build server (think this has to be a fixed folder until update 4 of release manager is deployed) the token entries in the .config files are replaced (so our integration tests can use the newly deployed servers). This is a release management step in the release template.
Tests are run in the fixed folder on the build server (rather than the msbuild output directory) so the test wildcard needs to be changed in the tfs build template.
Quick final note we don't use that build directory variable and it's left at blank I'm not convinced this would work if it was set to a value...
The replacement of variables in config files with Release Management happens at deployment time and not at compile time.
When RM deployes your app it inserts the correct variables.
It sounds like you're hitting one of two issues:
You need to include the .token file in your project and make sure it's set to Copy Always, so that it gets copied to the build output folder.
If you're building a web application, I've seen a bug in the release build process template that doesn't touch the contents of the _PublishedWebsites folder. I don't know if it's been fixed in Update 4 or not, but it was definitely still a problem in earlier versions.

Deployment of Jar using Ant and OJDeploy for packaging ADF

I'm trying to Deploy a Jar File from an ANT script (with OjDeploy), which compiles successfully. But when I run the main project (Which has the Jar dependency), I get a huge incident, when I analysed the incident log, it says
"Caused by: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist"
I analysed both the jar files (One generated by the ANT script and the other generated from Jdev). I couldn't find any difference b/w Manifest of those two jars. The other folders are also the same, In other words, both are almost the same, or I'm not able to figure out the difference between the two jar files generated.
I know, I'm missing something, config of build.xml or something, but not able to figure out the exact problem.
Thanks,
Shiva Shankar
My guess is that the problem is not in the JAR file but rather in the project that consumes it.
Seems like the DB connection in that project is different than the one in your JAR project - which causes one of the tables that is needed in the DB not be found.
I figured out a way to solve the problem. Not sure what was the cause of this issue, but a couple of changes made both to JAR/EAR build scripts set the things right
While building JAR files:
Uncheck "Make this the project build file" while creating the ANT build file, while the "Include Packaging Tasks (uses OjDeploy)" must be checked.
Remove "nocompile" parameter from tag in the OjDeploy.
While Building EAR files:
Create EAR in the view controller project.
Go to the View Controller Project Properties-> Project Source Path -> Resources, remove the newly created build file dependency, which specifies that the build file is for the whole project and not for the individual project.
Remove "Project" parameter from tag in the OjDeploy. (Ensures to build for the whole application)
Remove "nocompile" parameter from tag in the OjDeploy.
These are the exhaustive set of changes, which I made to ensure the ANT files are building correctly, if you get any other errors after this EAR is deployed, then its definitely due to code, EO/VO or DB related.
Thanks for all the help!!
Shiva Shankar

TFS build problem: missing assembly in test output folder

I am trying to integrate unit test cases with a TFS build in our new solution. I've include the following configuration line in my TFSBuild.proj
<ItemGroup>
<TestContainer Include="$(OutDir)\%2aTest.dll" />
</ItemGroup>
Which I think is the correct configuration since I only have 1 test project. However, when I do this, some dll is missing in the output folder of the test case, hence failing most of my test case. Has anyone run into this problem before?
Thanks!
Either reference the project for the missing file from the test project, or add the missing file as a deployment item in your .testrunconfig file.
MSTest only copies the libraries it thinks it needs to to the test folder.

Resources