I am trying to run the following scaffold the project is in .net 5. and I get this error
All my projects say
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
The one project that references efcore
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="5.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="5.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.4">
Error
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Internal.SemanticVersionComparer' from assembly 'Microsoft.EntityFrameworkCore, Version=5.0.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
at Microsoft.EntityFrameworkCore.Design.OperationExecutor..ctor(IOperationReportHandler reportHandler, IDictionary args)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at Microsoft.EntityFrameworkCore.Tools.ReflectionOperationExecutor..ctor(String assembly, String startupAssembly, String projectDir, String dataDirectory, String rootNamespace, String language, String[] remainingArguments)
at Microsoft.EntityFrameworkCore.Tools.Commands.ProjectCommandBase.CreateExecutor(String[] remainingArguments)
at Microsoft.EntityFrameworkCore.Tools.Commands.DbContextScaffoldCommand.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.<Configure>b__0(String[] args)
at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Exception has been thrown by the target of an invocation.
Saffold Command
Scaffold-DbContext "Server=1.1.1.1,1433;Initial Catalog=First;Persist
Security Info=False;User
ID=data;Password=data;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;Connection
Timeout=30;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir
Model/DB -Force -Context S3Context -Project S3.Core.DataSync.Framework
-t Data,SyncSales
I have 3 projects 1 project containing EF Core. If I load all three projects and set the project that has references to EF Core as "Set as Startup" I no longer have this issue. As soon as I set what should be the the startup project I get this error
Related
I have the following connection string that is used by a generated EF model. It works correctly on my local machine but when I deploy, I get the error below. I have look at the URL referenced many time on SO: http://blogs.teamb.com/craigstuntz/2010/08/13/38628/ and if it has the answer in it, I don't see it for my case.
I'm pasting the error below
<add name="svcodecampEntitiesAllTables" connectionString="metadata=res://*/EFModel.ModelAllTables.csdl|res://*/EFModel.ModelAllTables.ssdl|res://*/EFModel.ModelAllTables.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=svcc;integrated security=True;persist security info=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
{"message":"An error has occurred.","exceptionMessage":"Unable to load the specified metadata resource.","exceptionType":"System.Data.MetadataException","stackTrace":" at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)\r\n at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource..ctor(String originalPath, String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)\r\n at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)\r\n at System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)\r\n at System.Data.Metadata.Edm.MetadataCache.SplitPaths(String paths)\r\n at System.Data.Common.Utils.Memoizer`2.<>c__DisplayClass2.<Evaluate>b__0()\r\n at System.Data.Common.Utils.Memoizer`2.Result.GetValue()\r\n at System.Data.Common.Utils.Memoizer`2.Evaluate(TArg arg)\r\n at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections)\r\n at System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection()\r\n at System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor)\r\n at System.Data.Objects.ObjectContext..ctor(EntityConnection connection)\r\n at System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel()\r\n at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel()\r\n at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()\r\n at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)\r\n at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()\r\n at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()\r\n at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()\r\n at System.Linq.Queryable.Select[TSource,TResult](IQueryable`1 source, Expression`1 selector)\r\n at WebAPI.rest.AttendeesDashboardController.Get(String userSearch, Nullable`1 presentersOnly, Nullable`1 currentCodeCampYearOnly, Nullable`1 start, Nullable`1 limit) in c:\\VCProject\\SVCodeCampWeb\\WebAPI\\rest\\AttendeesDashboardController.cs:line 97\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()\r\n at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)"}
I had this problem too. I fixed it by explicitly naming the assembly that contains the model.
So, if your model is in "Product.DAL.dll", instead of:
metadata=res://*/EFModel.ModelAllTables.csdl|...
put:
metadata=res://Product.DAL/EFModel.ModelAllTables.csdl|...
for all 3 metadata resources
You must add reference to your project that contains the edmx diagram and change the connection string in the Nunit project
Change
<add name="ContainerName" connectionString="metadata=res://*/Diagram.csdl|re.....
By the name of the library in the 3 places in the metadata
<add name="ContainerName"connectionString="metadata=res://File.Data/Diagram.csdl|res://File.Data/Diagra...
"File.Data" is File.Data.dll, library generated by the project that contains the diagram
I have the same problem and solved by running custom tool. Right click on Model.tt file and click on run custom tool and repeat the same for context.tt file and Model.edmx file. Rebuilding the application will works.
When using EF 4.3.1 migrations every time i need to add a migration or update database i have to use the StartUpProject parameter. Can I set this somewhere so I don't have to keep doing this? I don't want to set my data project as the start up project. My context and migrations are in different projects if that makes a difference.
Exception thrown when not using StartpProject parameter:
update-database -verbose
Using NuGet project 'Data.Deployment'.
Using StartUp project ''.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
--- End of inner exception stack trace ---
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at System.Management.Automation.ComMethod.InvokeMethod(PSMethod method, Object[] arguments)
Exception has been thrown by the target of an invocation.
At least with Entity Framework 6, to specify the Startup Project use the -StartUpProjectName parameter with update-database:
update-database -StartUpProjectName <String>
You can use the get-help command within Package Manager Console to view possible parameters for commands:
get-help update-database -detailed
Use the StartupProject parameter: Update-database -StartupProject "PROJECTNAME"
I'm not sure if this is what you're talking about, but you can set the default project in the Package Manager Console to the project where your Migrations config resides in; it's the rightmost dropdown list.
This way I've never had to provide the startup project as an argument.
A clean way around this is to attach a Test Project to the solution.
Even if you don't want to write lots of unit tests, it's an appropriate start-up project for a data layer namespace or similar.
That makes your start up issue cleaner, the package manager applies to the whole solution IIRC - so make sure the default project is the one with the migrations folder in it.
Today EF4.3.1 released.
http://blogs.msdn.com/b/adonet/archive/2012/02/29/ef4-3-1-and-ef5-beta-1-available-on-nuget.aspx.
Follow the blog: http://thedatafarm.com/blog/data-access/using-ef-migrations-with-an-existing-database/. I firstly run:add-migration initial but throw exception as below and no create folder migrations:
PM> add-migration initial
System.Reflection.TargetInvocationException: 调用的目标发生了异常。 ---> System.ArgumentException: 参数不正确。 (异常来自 HRESULT:0x80070057 (E_INVALIDARG))
--- 内部异常堆栈跟踪的结尾 ---
在 System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
在 System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
在 System.Management.Automation.ComMethod.InvokeMethod(PSMethod method, Object[] arguments)
调用的目标发生了异常。
thus, I run Enable-migrations firstly. the folder migrations with Configuration.cs created.
I checked the database, under system tables without dbo._migrationhistory table.
then I run add-migration initial again. throw the same exception Mentioned before.
the Domain model in a project and the datacontext in another project which locate in DAL layer.
in my existing database Security there are several table such as role ,user and so on.
but no migration-history table.
there is only Iset Navigators in my datacontext. no match database tables.
My problem is how to get migration-history table and set up migration?
I finally found that if move the project out of solution Folder. it will work fine. maybe it's a bug.
When I try to use nunit-console.exe to run all the tests in a solution file as such:
nunit-console.exe MyProject.sln
I get the following exception (shown below). However when run the console runner on ANY of the projects in my folder structure, the runner works just fine and never gives me the following exception. I also am pretty certain that the version of the nunit library that I am linking to is the same as the runner that I am using. Also, my solution doesn't reference any projects that are outside the directory structure containing my .sln file.
Does anyone have any clue what I can do!? :(
Thanks!
Phil
NUnit version 2.5.10.11092
Copyright (C) 2002-2009 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.
Runtime Environment -
OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1
CLR Version: 4.0.30319.1 ( Net 4.0 )
ProcessModel: Default DomainUsage: Default
Execution Runtime: net-4.0
Unhandled Exception:
System.IO.FileLoadException: Could not load file or assembly 'nunit.framework, Version=2.5.10.11092, Culture=neutral, Pu
blicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The located assembly's manifest definition does not match the
assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'nunit.framework, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77'
Server stack trace:
at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount,
IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInsta
ntiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHa
ndle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethod
Arguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope
, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilte
rType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMeth
odInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken,
Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecorate
dTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
at NUnit.Core.CoreExtensions.InstallAdhocExtensions(Assembly assembly)
at NUnit.Core.Builders.TestAssemblyBuilder.Load(String path)
at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, Boolean autoSuites)
at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, String testName, Boolean autoSuites)
at NUnit.Core.TestSuiteBuilder.Build(TestPackage package)
at NUnit.Core.SimpleTestRunner.Load(TestPackage package)
at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
at NUnit.Core.RemoteTestRunner.Load(TestPackage package)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server,
Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExec
uteInContext)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at NUnit.Core.TestRunner.Load(TestPackage package)
at NUnit.Util.TestDomain.Load(TestPackage package)
at NUnit.ConsoleRunner.ConsoleUi.Execute(ConsoleOptions options)
at NUnit.ConsoleRunner.Runner.Main(String[] args)
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Try using the Fusion Log Viewer to see what assembly is failing to load. It should tell you not only what file it is failing on, but where it tried looking for that file.
In my case nunit-console.exe did not respect the assembly redirection from web|app.config. unless you provide /domain=multiple
My Problem:
EntityFrameworkTesting.Moq -> requests Moq, Version=4.2.1409.1722
I had already a newer assembly referenced.
The solution for me was to add /domain=multiple parameter. see the NUnit docs
So I run:
D:\tools\NUnit-2.6.4\bin\nunit-console.exe %SOLUTION_PATH%\Project.sln /config:Release /framework:net-4.0 /domain=multiple /xml=nunit-result.xml
I'm trying to get TeamCity to run NUnit tests as set up in an NAnt script as follows:
<nunit2>
<formatter type="Xml"
usefile="true"
extension=".xml"
outputdir="${BuildArea.ReportsDir}" />
<test assemblyname="${BuildArea.OutputDir}\Common.Tests.dll"
appconfig="src\Common.Tests\Tests.config" />
</nunit2>
Manually running the build script from the command line on the buildserver/agent machine runs the tests just fine so i know that there's no problem with the build script itself. However when a build runs from within TeamCity i always get the error:
"Could not locate the assembly nunit.Framework"
I've come across a related post (http://devnet.jetbrains.net/message/5211436#5211436) which recommends placing nunit.framework at the same location as the dll containings the tests but i was doing this already and i'm still getting the same error. Installing to the GAC is not an option.
Anyone has any idea how to fix this? I've spent hours trying to figure out what might be the problem but i can't see what i might be doing wrong.
Thanks
Exact error and stack trace follows:
[23:48:02]: Start TeamCity NUnit Test Runner
[23:48:02]:
NUnit Error: System.IO.FileNotFoundException: Could not load file or assembly 'nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The system cannot find the file specified.
File name: 'nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77'
Server stack trace:
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at NUnit.Core.TestFramework.FromAssembly(Assembly assembly)
at NUnit.Core.Builders.TestAssemblyBuilder.Load(String path)
at NUnit.Core.Builders.TestAssemblyBuilder.Build()
at NUnit.Core.Builders.TestAssemblyBuilder.Build(String testName)
at NUnit.Core.TestSuiteBuilder.Build(String assemblyName, String testName)
at NUnit.Core.SimpleTestRunner.Load(String assemblyName, String testName)
at NUnit.Core.SimpleTestRunner.Load(String assemblyName)
at NUnit.Core.ProxyTestRunner.Load(String assemblyName)
at NUnit.Core.ProxyTestRunner.Load(String assemblyName)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at NUnit.Core.TestRunner.Load(String assemblyName)
at JetBrains.TeamCity.NUnitLauncher.NUnitRunner.LoadTest(String testAssembly, String testName, TestRunner runner) in c:\Agent\work\e34bdcb45e12f223\src\NUnitLauncher\src\NUnit-2.2\NUnitRunner.cs:line 33
at JetBrains.TeamCity.NUnitLauncher.AssemblyTest.LoadTestDomain() in c:\Agent\work\e34bdcb45e12f223\src\NUnitLauncher\src\AssemblyTest.cs:line 71
at JetBrains.TeamCity.NUnitLauncher.LoadTestDomainAction.Action(AssemblyTest test) in c:\Agent\work\e34bdcb45e12f223\src\NUnitLauncher\src\LoadTestDomainAction.cs:line 14
at JetBrains.TeamCity.NUnitLauncher.TryOneAssemblyTest.Action() in c:\Agent\work\e34bdcb45e12f223\src\NUnitLauncher\src\TryOneAssemblyTest.cs:line 18
at JetBrains.TeamCity.NUnitLauncher.TryOneAssembly.Do() in c:\Agent\work\e34bdcb45e12f223\src\NUnitLauncher\src\TryOneAssembly.cs:line 31
In your runner properties page, have you set Nant home to anything? We use %env.NANTHOME%. Be aware that it is case sensitive.
We also had to create a separate unit-test target for teamcity, so we call targets : clean compile run-unit-tests-teamcity.
Below is an extraction of our targets, tidied up a bit.
<target name="run-unit-tests">
<property name="test.executable" value="tools\nunit\nunit-console.exe"/>
<property name="test.args" value="${test.assemblies} /xml="${build.fullpath}\test-reports\${prefix}_UnitTests.xml" /nologo /exclude=WetTest" dynamic="true"/>
<call target="do-unit-tests"/>
</target>
<target name="run-unit-tests-teamcity">
<property name="test.executable" value="${teamcity.dotnet.nunitlauncher}"/>
<property name="test.args" value="v2.0 MSIL NUnit-2.4.6 /category-exclude:WetTest ${test.assemblies}" dynamic="true"/>
<call target="do-unit-tests"/>
</target>
<!-- Run each of the unit tests in their own directory by project-->
<target name="do-unit-tests">
<!-- Run the unit tests for component1 -->
<property name="prefix" value="${prefix.component1}"/>
<property name="test.assemblies" value="component1.Common.dll component1.a.dll component1.b.dll component1.c.dll etc.dll"/>
<property name="test.assembly.dir" value="${build.dir}\${prefix.component1}" />
<call target="do-unit-test-single-project" />
<!-- Run the unit tests for component2 -->
<property name="prefix" value="${prefix.component2}"/>
<property name="test.assemblies" value="component2.Common.dll component2.a.dll component2.b.dll component2.c.dll etc.dll"/>
<property name="test.assembly.dir" value="${build.dir}\${prefix.component2}" />
<call target="do-unit-test-single-project" />
</target>
<target name="do-unit-test-single-project">
<mkdir dir="${build.dir}\test-reports" />
<!-- Ensure all tests have the default test config -->
<copy file="${build.dir}\${prefix.component1}\Tests.config" tofile="${test.assembly.dir}\Tests.config" />
<echo message="Starting NUnit code coverage run..."/>
<property name="test.failed" value="false"/>
<trycatch>
<try>
<ncover program="${path::get-full-path('tools\NCover\NCover.Console.exe')}"
commandLineExe="${test.executable}"
commandLineArgs="${test.args}"
workingDirectory="${build.dir}\${prefix}"
coverageFile="${build.fullpath}\test-reports\${prefix}_Coverage.xml"
logFile="${build.fullpath}\test-reports\${prefix}_coverage.log"
>
<assemblies basedir="${build.dir}\${prefix}">
<include name="${test.assemblies}"/> <!-- Only create the coverage for the specific project's assemblies -->
</assemblies>
</ncover>
</try>
<catch property="failure">
<echo message="At least one test failed: ${failure}"/>
<property name="fail.message" value="${failure}"/>
<property name="test.failed" value="true"/>
</catch>
</trycatch>
<call target="create-coverage-report"/>
</target>
<target name="create-coverage-report">
<ncoverexplorer program="tools\NCoverExplorer\NcoverExplorer.Console.exe"
projectName="NCoverExplorer"
reportType="4"
outputDir="${build.dir}\test-reports"
xmlReportName="${prefix}_CoverageReport.xml"
htmlReportName="${prefix}_CoverageReport.html"
mergeFileName="${prefix}_CoverageMerge.xml"
showExcluded="True"
satisfactoryCoverage="80" >
<fileset basedir="${build.dir}\test-reports">
<include name="${prefix}_Coverage.xml"/> <!-- Create a coverage report for each project group-->
</fileset>
<exclusions>
<exclusion type="Namespace" pattern="*.Tests" />
</exclusions>
</ncoverexplorer>
</target>