我有一个我正在开发的Asp.Net MVC Web应用程序.我在我的开发工作站上安装了TeamCity,并且一直在运行CI构建.一切都很好.我想将TeamCity从我的机器上移开,然后移到刚刚交付的新dev/build服务器上.我不想将Visual Studio安装到构建服务器上.但它接缝是msbuild无法构建Web应用程序项目.
E:\ TeamCity\buildAgent\work\48e528785fe346fa\src\Web\Web.csproj(489,11):错误MSB4019:导入的项目"C:\ Program Files\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft找不到.WebApplication.targets".确认声明中的路径是否正确,以及该文件是否存在于磁盘上.
我在谷歌上发现了一些点击,但没有什么可以接受的.建议是安装Visual Studio,或将某些目录从Visual Studio复制到服务器等.
我该怎么做才能使TeamCity在dev/build服务器上构建我的项目.
如何在深层lamda表达式中检查空值?
比方说,我有一个嵌套了几层深度的类结构,我想执行以下lambda:
x => x.Two.Three.Four.Foo
Run Code Online (Sandbox Code Playgroud)
如果Two,Three或Four为null,我希望它返回null,而不是抛出System.NullReferenceException.
public class Tests
{
// This test will succeed
[Fact]
public void ReturnsValueWhenClass2NotNull()
{
var one = new One();
one.Two = new Two();
one.Two.Three = new Three();
one.Two.Three.Four = new Four();
one.Two.Three.Four.Foo = "blah";
var result = GetValue(one, x => x.Two.Three.Four.Foo);
Assert.Equal("blah", result);
}
// This test will fail
[Fact]
public void ReturnsNullWhenClass2IsNull()
{
var one = new One();
var result = GetValue(one, x => x.Two.Three.Four.Foo);
Assert.Equal(null, result);
}
private TResult GetValue<TModel, TResult>(TModel model, …Run Code Online (Sandbox Code Playgroud) 我试图使用NHibernate查询我的一个域类上的IList <string>属性.这是一个简单的例子来演示:
public class Demo
{
public Demo()
{
this.Tags = new List<string>();
}
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual IList<string> Tags { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
映射如下:
<class name="Demo">
<id name="Id" />
<property name="Name" />
<bag name="Tags">
<key column="DemoId"/>
<element column="Tag" type="String" />
</bag>
Run Code Online (Sandbox Code Playgroud)
我能够保存和检索就好了.现在查询我的域类的实例,其中Tags属性包含指定的值:
var demos = this.session.CreateCriteria<Demo>()
.CreateAlias("Tags", "t")
.Add(Restrictions.Eq("t", "a"))
.List<Demo>();
Run Code Online (Sandbox Code Playgroud)
导致错误:收集不是关联:Demo.Tags
var demos = (from d in this.session.Linq<Demo>()
where d.Tags.Contains("a")
select d).ToList();
Run Code Online (Sandbox Code Playgroud)
导致错误:Objct引用未设置为对象的实例. …
我正在使用Fluent Nhibernate的1.0 RTM,以及3.0版本的NHibernate.为此,我需要将以下内容添加到我的.config文件中:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="NHibernate" culture="neutral" publicKeyToken="aa95f207798dfdb4"/>
<bindingRedirect oldVersion="2.1.0.4000" newVersion="3.0.0.1001"/>
</dependentAssembly>
</assemblyBinding>
Run Code Online (Sandbox Code Playgroud)
这在使用TestDriven.net插件运行集成测试时效果很好,但在NUnit gui或console runner中失败并出现以下错误:
System.IO.FileLoadException:无法加载文件或程序集'NHibernate,Version = 2.1.0.4000,Culture = neutral,PublicKeyToken = aa95f207798dfdb4'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)
如何让NUnit尊重我的bindingRedirect并成功运行我的集成测试?
我需要让NHibernate 2.1与oracle数据库通信.我被要求使用Oracle 10g客户端.尝试构建会话工厂时出现以下错误:
无法将类型为"Oracle.DataAccess.Client.OracleConnection"的对象强制转换为"System.Data.Common.DbConnection".
我不记得NHibernate 2.01出现此错误.我试图让服务器管理员安装11g客户端,但看起来这是一场失败的战斗.
以下是我的web.config中的重要部分:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="Oracle.DataAccess" fullName="Oracle.DataAccess, Version=10.2.0.100, Culture=Neutral, PublicKeyToken=89b483f429c47342"/>
</assemblyBinding>
</runtime>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property>
<property name="connection.connection_string_name">Demo</property>
<property name="show_sql">false</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
</session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)
完整堆栈跟踪
at NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Prepare()
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper)
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory)
at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at ConsoleApplication6.Program.Main(String[] args) in C:\\Dev\\Temp\\ConsoleApplication6\\Program.cs:line 26
Run Code Online (Sandbox Code Playgroud) 假设我有一个服务接口:
public interface IFooService
{
void DoSomething();
}
Run Code Online (Sandbox Code Playgroud)
并且该服务的具体实现是通用的:
public class FooService<TRequestingClass> : IFooService
{
public virtual void DoSomething() { }
}
Run Code Online (Sandbox Code Playgroud)
我还有一些需要IFooService实例的其他类:
public class Bar
{
private IFooService _fooService;
public Bar(IFooService fooService)
{
this._fooService = fooService;
}
}
Run Code Online (Sandbox Code Playgroud)
我需要连接我的IoC容器,这样当创建Bar时,它会传递一个FooService <Bar>的构造函数参数.还有很多其他课程就像Bar一样.每个人都可能需要传递给他们的FooService <TRequestingClass>实例,其中TRequestingClass是需要IFooService实例的类的类型.我不需要向IFooService的消费者公开这个怪癖.他们应该关心的是他们可以调用他们传递的IFooService的方法.他们不应该知道他们传递的IFooService的具体实现需要任何特殊的构造.
FooService <T>的可接受的替代方法是一个非泛型类,在其构造函数中包含一个字符串参数,该参数包含为其创建的类的名称.即:
public class FooService : IFooService
{
public FooService(string requestingClassName) { }
}
Run Code Online (Sandbox Code Playgroud)
如何通过这种方式连接我的IoC容器来构建依赖项?
如果你为什么我想要这样一个奇怪的结构而感到困惑,那么考虑当你得到一个用log4net.LogManager.GetLogger(typeof(SomeClass))创建的ILog时log4net如何工作得最好.我不想通过引用log4net来丢弃我的代码,所以我想编写一个简单的ILogger接口,并用这样的方式实现它:
public class GenericLogger<T> : ILogger
{
private readonly ILog log;
public GenericLogger()
{
this.log = log4net.LogManager.GetLogger(typeof(T));
}
public void Debug(object message)
{ …Run Code Online (Sandbox Code Playgroud) c# ×3
nhibernate ×3
linq ×2
.net ×1
asp.net-mvc ×1
hql ×1
icriteria ×1
lambda ×1
msbuild ×1
ninject ×1
nunit ×1
oracle ×1
oracle10g ×1
structuremap ×1
teamcity ×1