I can't figure out what I need to do to generate Fakes. In my test project I included a reference to the assembly that I want to fake. It added /Fakes/<assembly name>.fakes to my project and it built the project. There were a ton of warnings, but there are 0 errors and the build completed successfully. But it is not adding any reference to the generated .Fakes assembly.
Most of the warnings were things like cannot generate stubs or shims for an enum, or some private class is not visible to the fakes assembly. There's really only 1 class in the assembly that I want to Shim, and nothing that I want to Stub. So I edited the .fakes file:
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/"
Diagnostic="true">
<Assembly Name="[assembly name]">
<StubGeneration>
<Clear />
</StubGeneration>
<ShimGeneration>
<Clear />
<Add Namespace="[namespace that the 1 class I want to shim is in]" />
</ShimGeneration>
</Assembly>
</Fakes>
I cleaned and rebuilt the project, and I am still getting tons of warnings, and no errors, that it can't stub or shim classes that I have excluded in the .fakes file, and the .Fakes assembly is still not getting generated.
How do I actually I stop it from trying to create stubs and only creating shims for classes that are in a specific namespace? The information from http://msdn.microsoft.com/en-us/library/hh708916.aspx is, apparently, not correct.
Also, I removed the Version attribute from the Assembly element, but the warnings that I'm getting still include the version number in the namespace. What's up with that?
I found out what my problem was. I thought StubGeneration and ShimGeneration were supposed to be child elements of Assembly, but they aren't. They are supposed to be children of Fakes, and siblings of Assembly. After changing my .fakes file to this, it works:
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/"
Diagnostic="true">
<Assembly Name="[assembly name]" />
<StubGeneration>
<Clear />
</StubGeneration>
<ShimGeneration>
<Clear />
<Add Namespace="[namespace that the 1 class I want to shim is in]" />
</ShimGeneration>
</Fakes>
Related
VSTest, which is what TFS 2015 uses for unit-tests, wants to ignore application config/settings (app.config) by default. VSTest takes an optional "runsettings" configuration file, but it doesn't accommodate any information about an app.config file. Now, from the runsettings file, you can tell it to drop into "legacy" mode:
<RunSettings>
<MSTest>
<ForcedLegacyMode>true</ForcedLegacyMode>
</MSTest>
</RunSettings>
...and this will allow it to use the app.config file in the same directory (these are assemblies/libraries, so the configuration file is just named "app.config" rather than "application.exe.config"). However, it will not find included files. For example, I have a separate connection-strings file. It's included from the top of the app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings configSource="connectionStrings.config" />
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
I will get an error every time about how it can't find the file:
2016-09-21T18:36:12.2439565Z ##[error]Error Message:
2016-09-21T18:36:12.2439565Z ##[error] Test method Assembly.Project.Class threw exception:
2016-09-21T18:36:12.2595841Z ##[error]System.Configuration.ConfigurationErrorsException: Unable to open configSource file 'connectionStrings.config'. (D:\Agents\A3\_work\464b36816\TestResults\Definition_Host 2016-09-21 14_36_09\Out\Assembly.DLL.config line 7)
2016-09-21T18:36:12.2595841Z ##[error]Stack Trace:
Since it's only allowed to be relative (otherwise, you'll get another error), I've tried prepending ".\" (which seems like it works in other situations) and well as referencing the next few levels of directories above it, but it will not find the referenced connection-strings file.
Okay. So I wanted to inspect the execution logic in order to figure out what the working directory was. The TFS 2015 task that is initiating the tests is called VSTest.ps1. It refers to a cmdlet called "Invoke-PSTest" in order to call "vstest.console.exe" to actually run the tests. This exists absolutely nowhere on the disk as it's own file or in any psd1/psm1 files, so it must be provided by a binary assembly.
However, I'm also apparently avoiding providing a data-source/connection-string to the unit-tests the way that I am supposed to. After all, I'm having to use "legacy" mode in order to get VSTest to use my configuration file.
So, what is the proper way to provide application-configuration (such as a connection-string) to unit-tests? After-all, sometimes you actually need an external resource in order to properly test.
I've created a custom task to get me a three-part version number of my assembly that was built in MSBuild.
I've created a custom <Target Name="GetVersion"> for this, and it works nicely - the three-part version number(1.5.2) is stored into a ThreePartBuildNumber property in MSBuild.
But how do I tell MSBuild inside Visual Studio 2010 to call this target once it's compiled my assembly, and before creating my WiX Setup project (where I'd like to set the WiX install script's Product/#Version to this three-part version number automatically)?
How can I "plug" this new target into the usual VS 2010 build process?
Update:
OK, I've managed to get this into the *.wixproj file which is also a MSBuild file, really. In the <Target Name="BeforeBuild">, I can successfully determine the three-part version number, and it's stored inside a MSBuild property called ThreePartVersionNumber.
But how on earth can I now access this properly filled MSBuild property in my WiX setup? I tried setting <Product Version="$(var.ThreePartVersionNumber) ...>, but that doesn't work - it doesn't seem to find the variable.... neither works with the sys. or env. prefixes, either....
So how do I make this MSBuild property that has the information I need "visible" to the WiX installer script/XML ?!?!?!? I can't seem to see the forest for all those angle brackets .....
Use the /verbosity:d switch to get a full view of all the targets that were performed and their rough reason for being called (dependent-on). Identify the exact thing you want to be before or after or dependent upon. Besides using the depends attributes on your Target, there are also various properties that are used to collect dependencies for various purposes. You can identify these by using /preprocess and then looking up the Targets that catch your eye from the previous step.
I've found that specific answers often don't work, as the build situation is different for my language or the exact inclusion order matters or other minor things; so this is how I've found the real triggers in my case.
What I've done in the end:
inside my WiX setup project, in the myproject.wixproj MSBuild file, I've added a new custom task like this:
<UsingTask TaskName="GetThreePartVersion" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<AssemblyPath ParameterType="System.String" Required="true" />
<ThreePartVersion ParameterType="System.String" Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.Diagnostics" />
<Code Type="Fragment" Language="cs">
<![CDATA[
Log.LogMessage("Getting version details of assembly at: " + this.AssemblyPath, MessageImportance.High);
Version v = Version.Parse(FileVersionInfo.GetVersionInfo(this.AssemblyPath).FileVersion);
this.ThreePartVersion = v.ToString(3);
]]>
</Code>
</Task>
</UsingTask>
and then in the BeforeBuild target, I added these lines to call this task and define a WiX constant with the results:
<Target Name="BeforeBuild">
<GetThreePartVersion AssemblyPath="$(SolutionDir)Plugin\$(OutputPath)Swisscom.Vidia.Plugin.dll">
<Output TaskParameter="ThreePartVersion" PropertyName="ThreePartVersionNumber" />
</GetThreePartVersion>
<PropertyGroup>
<DefineConstants>ThreePartBuildVersion=$(ThreePartVersionNumber)</DefineConstants>
</PropertyGroup>
<Message Text="Three-part version: $(ThreePartVersionNumber)" />
</Target>
and now in my WiX project.wxs file, I can reference that constant that's been defined, and use it for the <Product Version="..." ... /> attribute:
<Product Id="*" Name="MyProject" Language="1033"
Version="$(var.ThreePartBuildVersion)" ......>
It took a bit of twiddling and a lot of trial & mostly error until I finally got it right - but this is the way it works for me now. Hope this might help some other soul some day....
I built my own project template. When a project is created with the template, a custom wizard is launched that allows the user to edit the project that was created.
The problem is that I also need to add some very simple nuget packages to the created project (just mvvmlight, MyToolkit and 1 other). To do this I added a WizardData element to my vstemplate with the right packages.
Here comes the problem: in order to launch my custom wizard, I need to put a reference to my wizard inside the WizardExtension element. But in order to install the nuget packages automatically I need to place a reference towards NuGet.VisualStudio.TemplateWizard inside my WizardExtension element, and the WizardExtension can only have one class that it will instantiate, but I have 2 that need to run.
So how do I solve this?
Here's the code that launches my own wizard. Now I just need the NuGet packages to install too:
<WizardExtension>
<Assembly>PartyTemplateWizard, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=7eb2f41084fd4cd5</Assembly>
<FullClassName>PartyTemplateWizard.Wizard</FullClassName>
</WizardExtension>
<WizardData>
<packages repository="template">
<package id="MvvmLight" version="4.1.27.0" />
<package id="MvvmLightLibs" version="4.1.27.0" />
<package id="MyToolkit" version="1.14.0" />
<package id="linqtotwitter" version="2.1.06" />
</packages>
</WizardData>
Does anyone have a solution?
Well, I came across the same issue and was disappointed to find no answer for this post. Now I've got the answer and I'm posting it.
There cannot be two wizard extensions. So you need to instantiate NuGet from your custom wizard (see below) and delegate all methods to this instance.
Add these lines to the RunStarted method:
Assembly asm = Assembly.Load("NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a");
wizard = (IWizard)asm.CreateInstance("NuGet.VisualStudio.TemplateWizard");
And, call the method on the instance like this:
wizard.RunStarted(automationObject, replacementsDictionary, runKind, customParams);
Similar way delegate to the wizard instance in all methods.
Instead of trying to place multiple references in one WizardExtension element - you can add multiple WizardExtension elements (one for each assembly reference).
For example:
<WizardExtension>
<Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
<FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName>
</WizardExtension>
<WizardExtension>
<Assembly>PartyTemplateWizard, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=7eb2f41084fd4cd5</Assembly>
<FullClassName>PartyTemplateWizard.Wizard</FullClassName>
</WizardExtension>
<WizardData>
<packages repository="extension" repositoryId="your-extension-id-here">
<package id="MvvmLight" version="4.1.27.0" />
<package id="MvvmLightLibs" version="4.1.27.0" />
<package id="MyToolkit" version="1.14.0" />
<package id="linqtotwitter" version="2.1.06" />
</packages>
</WizardData>
References used:
Xamarin Forms Templates (you can refer this vstemplate file in the repository)
Packages in Visual Studio templates
How to specify two wizard assemblies under tag in project template to create mvc4 application (vs2010)
Disclaimer: I have tested this on Visual-Studio-2015 only; not on Visual-Studio-2012 (although a quick look through the answers on this link seems to indicate that it is supported on VS2012 too)
I wonder if it's possible to make something like this...
I have a project in VS2012 that uses two referenced VS projects (DLLs are being created during compilation) and some other DLLs (external libraries etc.). Now I want to clean up my compilation and place DLLs in two folders: e.g. Internals and Externals.
How to make it possible? The problem is that my compiled .exe app file wants the DLLs to be placed in the main folder (near to it) - so if it needs to load the library from DLL it crashes...
I tried to find something in the web, but ppl only ask about copying DLLs from the reference folders into the output folder. But that's not what I want to do:/
Ok, I have found a solution. I need to add a new item app.config and specify privatePaths:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="InternalsFolder;ExternalsFolder" />
</assemblyBinding>
</runtime>
</configuration>
I am trying to use Gallio (v3.1)/MbUnit/NCover to run a unit test in my C# code, as part of the build process for my continuous integration system.
I can get Gallio.Echo.exe to execute the tests and output an XML file (albeit it does seem to be checking all .dll files in the folder == approx. 6.5MB .xml file!!), but when I try to get NCover to link in also, it goes bang.
THEN: I tried to use the NAnt task using instructions from here, such as:
<gallio result-property="testrunner.exit-code"
application-base-directory="bin/debug"
runner-type="NCover"
failonerror="false"
report-name-format="gallio-MyTestProject"
report-types="xml"
report-directory="bin/debug">
<runner-property value="NCoverArguments='//q //ea CoverageExcludeAttribute //a MyTestProject.dll'" />
<runner-property value="NCoverCoverageFile='coverage-MyTestProject.xml'" />
<assemblies>
<include name="bin/debug" />
</assemblies>
</gallio>
but I get the following error on my command-line:
Element Required! There must be a least one 'files' element for <gallio ... />.
I have tried to specify the .dll file that I'd like to check, but it still comes up with this message. Any suggestions are most appreciated!
<assemblies> has been changed to <files>