从MSBuild调用任务时遇到问题- 以下是我所做的详细信息-
1)我有C#WCF项目,运行的服务很少。我将这些服务托管在在本地计算机上运行的Local Host.Service“ http://localhost:59605/HotfixDatabaseAccess.svc”上。 它具有函数“ IHotfixDatabaseAccess.GetComponentDetailsForHF()”,使用此服务的客户端可以调用该函数。
2)我创建了另一个C#库项目,并在其中添加了“ HotfixDatabaseAccess.svc”服务引用。 添加服务后,它会创建App.config文件,其中提到了服务的所有端点。 App.config-内容
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IHotfixDatabaseAccess" />
</basicHttpBinding>
<wsHttpBinding>
<binding name="WSHttpBinding_IHotfixDatabaseAccess" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:59605/HotfixDatabaseAccess.svc/secure"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHotfixDatabaseAccess"
contract="HotfixDatabaseAccess.IHotfixDatabaseAccess" name="WSHttpBinding_IHotfixDatabaseAccess">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="http://localhost:59605/HotfixDatabaseAccess.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IHotfixDatabaseAccess"
contract="HotfixDatabaseAccess.IHotfixDatabaseAccess" name="BasicHttpBinding_IHotfixDatabaseAccess" />
</client>
</system.serviceModel>
</configuration>
此C#项目包含设计为Task的类,可以从MSBuild项目文件中调用这些类。
namespace BuildDeliverablesTask
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using CustomTasks.HotfixDatabaseAccess;
using Microsoft.Build.Framework;
using Microsoft.Build.Tasks;
using Microsoft.Build.Utilities;
public class BuildDeliverables : Task
{
public override bool Execute()
{
using (HotfixDatabaseAccessClient hfdbClient = new HotfixDatabaseAccessClient())
{
hfdbClient.GetComponentDetailsForHF(); //Called Service Function.
}
}
}
}
构建此项目后,将提供“ BuildDeliverablesTask.dll”和“ BuildDeliverablesTask.dll.config”文件。 “ BuildDeliverables.dll.config”的内容与App.config的内容相同。
3)我的意图是从MSBuild Proj文件调用此BuildDeliverables任务。 这是我编写的MSBuild“ BuildDeliverables.proj”文件-
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
<UsingTask AssemblyFile="BuildDeliverablesTask.dll" TaskName="BuildDeliverables" />
<Target Name="BuildDeliverableSoultions">
<BuildDeliverables/> <!-- Task is Called here -->
</Target>
</Project>
4)现在,当我尝试调用“ BuildDeliverables.proj”时,使用MSBuild会给我错误 InvalidOperationException:无法找到引用对立的默认终结点元素 ct ServiceModel客户端配置部分中的“ HotfixDatabaseAccess.IHotfixDatabaseAccess”。这可能是因为找不到您的应用程序的配置文件,或者是因为在客户端元素中找不到与该合同匹配的端点元素。\ r 下面是错误详细信息-
"BuildDeliverables.proj" (default target) (1) ->
(BuildDeliverableSoultions target) ->
BuildDeliverables.proj(13,5): error : InvalidOperationException: Could not find default endpoint element that references contra
ct 'HotfixDatabaseAccess.IHotfixDatabaseAccess' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.\r
BuildDeliverables.proj(13,5): error : at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint ser
viceEndpoint, String configurationName)\r
BuildDeliverables.proj(13,5): error : at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Confi
guration configuration)\r
BuildDeliverables.proj(13,5): error : at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)\r
BuildDeliverables.proj(13,5): error : at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, Endpo
intAddress address)\r
BuildDeliverables.proj(13,5): error : at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, Endpoint
Address remoteAddress)\r
BuildDeliverables.proj(13,5): error : at System.ServiceModel.ConfigurationEndpointTrait`1.CreateSimplexFactory()\r
BuildDeliverables.proj(13,5): error : at System.ServiceModel.ConfigurationEndpointTrait`1.CreateChannelFactory()\r
BuildDeliverables.proj(13,5): error : at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrai
t)\r
BuildDeliverables.proj(13,5): error : at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()\r
BuildDeliverables.proj(13,5): error : at System.ServiceModel.ClientBase`1..ctor()\r
有人可以帮助我解决此错误吗?