问题应该是什么:
这是我ModuleCompilation.targets文件的内容:
<ItemGroup>
<ConfigFilesToMove Include="bin\$(Configuration)\*.config"/>
</ItemGroup>
<Target Name="AfterBuild">
<Message Text="Message for AfterBuild" />
<Move SourceFiles="@(ConfigFilesToMove)" DestinationFolder="bin\$(Configuration)\Configuration\" />
</Target>
Run Code Online (Sandbox Code Playgroud)
消息已写入控制台,但文件未移动,怎么回事?
原始问题(您可以忽略):
我在csproj文件中包含了一个导入,以从另一个文件导入任务:
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\ModuleCompilation.targets" />
Run Code Online (Sandbox Code Playgroud)
现在,这是我的ModuleCompilation.targets文件的内容:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="AfterBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<BaseFiles Include="bin\$(Configuration)\Libraries\ModuleBase*"/>
<ConfigFilesToMove Include="bin\$(Configuration)\*.config"/>
<OtherFilesToMove Include="bin\$(Configuration)\*" Exclude="bin\$(Configuration)\$(MSBuildProjectName)*" />
</ItemGroup>
<Target Name="AfterBuild">
<Message Text="AfterBuild" />
<Move SourceFiles="@(ConfigFilesToMove)" DestinationFolder="bin\$(Configuration)\Configuration\" />
<Move SourceFiles="@(OtherFilesToMove)" DestinationFolder="bin\$(Configuration)\Libraries\" />
<Message Text="bin\$(Configuration)\Libraries\ModuleBase*" />
<Delete Files="@(BaseFiles)" />
</Target>
</Project>
Run Code Online (Sandbox Code Playgroud)
生成或重建时,控制台中确实显示“ AfterBuild”消息,并且确实生成了所有文件,但是它们并没有从Debug文件夹移动到我想要的位置。
如果我重建projet,文件会被移动,我想是因为已经存在,但是我想先生成文件然后再移动,但我不想让它们已经存在!
我一定缺少真正明显的东西,你能帮我吗?
编辑:
好的,所以我进行了一些测试,并且可以正常工作:
<ConfigFilesToMove Include="bin\Debug\App.config"/>
Run Code Online (Sandbox Code Playgroud)
虽然这不是:
<ConfigFilesToMove Include="bin\Debug\*.config"/>
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么? …
对不起,如果我的问题很愚蠢,但我有这样的代码:
public Object1 Method1(Object2 parameter)
{
try
{
return this.linkToMyServer.Method1(parameter);
}
catch (Exception e)
{
this.Logger(e);
}
return null;
}
public Object3 Method2(Object4 parameter)
{
try
{
return this.linkToMyServer.Method2(parameter);
}
catch (Exception e)
{
this.Logger(e);
}
return null;
}
/* ... */
public ObjectXX Method50(ObjectXY parameter)
{
try
{
return this.linkToMyServer.Method50(parameter);
}
catch (Exception e)
{
this.Logger(e);
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
我想你看到的模式.有没有一种很好的方法只有一次尝试catch并在这个try catch中传递泛型方法?
本能地我会使用代表,但代表必须拥有相同的签名吗?
提前致谢.
问候.
这是我经常遇到的一个巨大的设计问题,我认为这是因为我不理解OOP.
这是基本属性的类:
public class BasePropety {}
Run Code Online (Sandbox Code Playgroud)
这是我的DerivedProperty的类型:
public class DerivedProperty : BaseProperty
{
public AClass A { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是我的基类:
public class BaseClass
{
public BaseProperty Property { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是我的派生类:
public class DerivedClass : BaseClass
{
public DerivedProperty Property { get; set; }
public void MethodExample()
{
AClass aValue = this.Property.A;
}
}
Run Code Online (Sandbox Code Playgroud)
我当然可以对我的财产进行强制转换,但这很烦人:
public class DerivedClass : BaseClass
{
public void MethodExample()
{
var typedProperty = (DerivedProperty) this.Property;
AClass aValue = typedProperty.A;
}
} …Run Code Online (Sandbox Code Playgroud)