我的最终目标是创建一个跨平台(非Web)控制台应用程序,所以我现在正在探索.NET Core.
在我之前的.NET项目中,我在Visual Studio中进行了所有开发,但我还创建了一个批处理/ MSBuild文件,因此我只需单击一下即可构建整个项目(包括设置,NuGet包,带二进制文件的zip文件等).这是以前项目的一个例子.
最后,我想用我的.NET Core测试项目做类似的事情.
但是现在我在第一步失败了:我无法在Visual Studio之外构建它,因此结果可以在没有安装.NET Core的另一台Windows机器上运行.
(在第一步中,我忽略了跨平台部分 - 我很乐意让它在Windows上运行)
我设法让它在Visual Studio 2015 Community Edition中运行如下:
在Visual Studio中创建新项目:"新建项目"⇒"Web"⇒"控制台应用程序(包)"
在Visual Studio中创建新的发布配置文件(菜单中的"Build"⇒"Publish").
这将创建一个PowerShell脚本(以及一个带有设置的XML文件)
当我再次在菜单中"构建"⇒"发布"时,Visual Studio显然会再次执行先前创建的PowerShell脚本.
结果略超过90 MB,由598个文件夹中的825个文件组成,如下所示:
当我将它复制到另一台机器上时(安装了Win 7/.NET 4/未安装的.NET Core ),它可以工作.
这个答案和这个答案听起来像我可以用来dnu publish通过命令行获得相同的结果.
据我所知,.NET的核心部分仍移动的目标,现在,所以显然dnu现在dotnet不是.
所以我尝试为它执行dotnet publish(并创建一个批处理文件):
dotnet publish "%~dp0\src\CoreTestVisualStudio" -c Release -r win7-x64 -o "%~dp0\release\cli"
Run Code Online (Sandbox Code Playgroud)
结果包含一个 …
我的问题类似于这个问题中描述的问题:
DataTemplate中的WPF MVVM按钮控件绑定
这是我的XAML:
<Window x:Class="MissileSharp.Launcher.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MissileSharp Launcher" Height="350" Width="525">
<Grid>
<!-- when I put the button here (outside the list), the binding works -->
<!--<Button Content="test" Command="{Binding Path=FireCommand}" />-->
<ListBox ItemsSource="{Binding CommandSets}">
<ListBox.ItemTemplate>
<DataTemplate>
<!-- I need the button here (inside the list), and here the binding does NOT work -->
<Button Content="{Binding}" Command="{Binding Path=FireCommand}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
它只是一个ListBox绑定到ObservableCollection<string>命名CommandSets(在ViewModel中).
此绑定有效(它显示集合中每个项目的按钮).
现在我想将按钮绑定到一个命令(FireCommand),该命令也在ViewModel中.
这是ViewModel的相关部分:
public class MainWindowViewModel : …Run Code Online (Sandbox Code Playgroud) 每当我使用了德国元音在过去一个HTML文件时,总是我被取而代之ä,ö根据等这个表.
我当时不知道编码,也没想过.
我只是"知道",当我只想用ä,ö等等.相反,在其他国家的许多计算机将无法正确显示变音.
当我通过放入<meta charset="utf-8">标题将UTF-8编码的HTML文件的字符集设置为UTF-8时,是否仍然需要替换äby ä,öby ö等等?
例如:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ÄÖÜäöüß</title>
</head>
<body>
ÄÖÜäöüß
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我将其保存在我的机器上的UTF-8编码的HTML文件中并在浏览器中查看时,所有的变音符都会正确显示.
但是我在德国,我机器上的所有东西都是德语,所以当然我的机器能够正确显示德国变形金刚.
我阅读了Joel的绝对最低每个软件开发人员,绝对必须知道Unicode和字符集(没有借口!),但这种编码对我来说是全新的.
根据我对编码,UTF-8和设置字符集的理解,我怀疑<meta charset="utf-8">在UTF-8编码的HTML文件中设置意味着我不再需要使用ä等等.
但我找不到一个明确说明的来源.
public Cursor set_datetime_next(Reminder r) {
String _newVal = "datetime('now', '+7 days')";
String[] args = { new Integer(r.getID()).toString() };
String query =
"UPDATE " + DBConst.TABLE
+ " SET " + DBConst.f_DATETIME_NEXT + "=" + _newVal
+ " WHERE " + DBConst.f_ID +"=?";
Log.i(TAG, query);
return db.rawQuery(query, args);
}
Run Code Online (Sandbox Code Playgroud)
我也试过传入datetime('now', '+7 days')作为绑定参数,这将无法工作,因为Android文档说:
这些值将绑定为字符串.
参考文献:
有没有办法按字母顺序对一些帖子进行排序,使用Jekyll?
我现在有这样的事情:
{% for post in site.categories.threat %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
它有效,但帖子混乱了.如果他们按字母顺序排序,我认为会更好看.
谢谢
我有一个WPF/MVVM应用程序,它包含一个带有几个按钮的窗口.
每个按钮都会触发对外部设备(USB导弹发射器)的调用,这需要几秒钟.
设备运行时,GUI被冻结.
(这没关系,因为应用程序的唯一目的是调用USB设备,而且当设备移动时你无论如何也无法做任何事情!)
唯一有点难看的是冻结的GUI在设备移动时仍然接受额外的点击.
当设备仍然移动并且我第二次点击同一按钮时,设备会在第一次"运行"完成后立即再次开始移动.
所以我想在单击一个按钮后立即禁用GUI中的所有按钮,并在按钮的命令运行完毕后再次启用它们.
我找到了一个看起来符合MVVM的解决方案.
(至少对我而言......请注意,我仍然是WPF/MVVM的初学者!)
问题是,当我调用与USB设备通信的外部库时,此解决方案不起作用(如:禁用按钮).
但是禁用GUI的实际代码是正确的,因为当我替换外部库调用时它确实有效MessageBox.Show().
我构建了一个最小的工作示例来重现问题(这里是完整的演示项目):
这是观点:
<Window x:Class="WpfDatabindingQuestion.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel>
<Button Content="MessageBox" Command="{Binding MessageCommand}" Height="50"></Button>
<Button Content="Simulate external device" Command="{Binding DeviceCommand}" Height="50" Margin="0 10"></Button>
</StackPanel>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
...这是ViewModel (使用RelayCommandJosh Smith的MSDN文章):
using System.Threading;
using System.Windows;
using System.Windows.Input;
namespace WpfDatabindingQuestion
{
public class MainWindowViewModel
{
private bool disableGui;
public ICommand MessageCommand
{
get
{
return new …Run Code Online (Sandbox Code Playgroud) (我最初在这篇评论中提出了这个问题,但Mark Seemann要我改为创建一个新问题.)
我正在开始一个新的应用程序(.NET Core,如果这很重要),现在我正在尝试决定如何进行日志记录.
普遍的共识似乎是日志记录是一个跨领域的问题,因此记录器不应该直接注入应该记录的类.
通常,有一个像下面这样的例子如何不这样做:
public class BadExample : IExample
{
private readonly ILogger logger;
public BadExample(ILogger logger)
{
this.logger = logger;
}
public void DoStuff()
{
try
{
// do the important stuff here
}
catch (Exception e)
{
this.logger.Error(e.ToString());
}
}
}
Run Code Online (Sandbox Code Playgroud)
相反,具有业务逻辑的类不应该知道记录器(SRP),并且应该有一个单独的类来执行日志记录:
public class BetterExample : IExample
{
public void DoStuff()
{
// do the important stuff here
}
}
public class LoggingBetterExample : IExample
{
private readonly IExample betterExample; …Run Code Online (Sandbox Code Playgroud) c# logging dependency-injection inversion-of-control cross-cutting-concerns
我正在建立一个基本的Github托管的Jekyll网站(这么简单,我甚至不打算改变默认主题).我有一个嵌套的网站,其中包含少量的第一层页面,我想在导航栏中显示(即默认的操作模式).我还有一些第二层页面,我不想破坏导航栏.
虽然多级导航系统会很好,但我试图避免使用插件.因此,我认为最简单的解决方案是完全从导航系统中排除第二层页面.
这是一个假设的页面结构(减去其他Jekyll文件):
jekyllsite
jekyllsite/bar
jekyllsite/bar/alice
jekyllsite/bar/alice/index.md
jekyllsite/bar/bob
jekyllsite/bar/bob/index.md
jekyllsite/bar/index.md
jekyllsite/baz
jekyllsite/baz/index.md
jekyllsite/foo
jekyllsite/foo/eggs
jekyllsite/foo/eggs/index.md
jekyllsite/foo/index.md
jekyllsite/foo/spam
jekyllsite/foo/spam/index.md
jekyllsite/index.md
Run Code Online (Sandbox Code Playgroud)
按照令人敬畏的降序排列,这就是我想要这样做的方式:
最好的情况,上下文敏感的导航(没有插件可能不会想到):访问jekyllsite/index.md时,我会得到一个单层导航栏,提供指向foo,bar和baz的链接.访问jekyllsite/bar/index.md时,我会在顶层看到一个包含foo,bar和baz的双层导航栏,第二层包含alice和bob.
下一个最佳选择是让我在全局范围内进行更改,以便只将顶级目录(foo,bar,baz)添加到导航栏.alice,bob,spam和eggs等子目录将自动从导航栏中排除.
最后(我认为这可能是最简单的)将是YAML frontmatter标志来排除页面.类似于nonav: true要排除的页面前端的东西.
这似乎是一个相当常见的用例,尽管我找不到任何看起来像这三个选项中的任何一个的短路径的东西.我希望更熟悉Jekyll的人有一个"阻力最小的道路"的答案.
我想测试一个具有高圈复杂度(叹气)的方法,我想在测试类中有一个类,以便方法测试类作为树中的节点出现.是否有可能与Nunit和如何?
MyEntityTests
|
L_ MyComplexMethodTests
L when_some_condition_than
L when_some_other_condition_than
[TestFixture]
public class MyEntityTests
{
[TestFixture]
public class MyComplexMethodTests
{
[Test]
public void when_some_condition_than() {}
etc.....
}
}
Run Code Online (Sandbox Code Playgroud) 我正在编写一个工具来将我的所有存储库从Bitbucket(支持Git和Mercurial)备份到我的本地计算机.
它已经适用于Mercurial,我这样做:
bareGit存储库相同)现在我正在尝试用Git做同样的事情.
我已经发现我不能直接pull访问裸存储库,而是应该使用它fetch.
所以我试了一下:
C:\test>git fetch https://github.com/SamSaffron/dapper-dot-net.git
remote: Counting objects: 1255, done.
remote: Compressing objects: 100% (1178/1178), done.
remote: Total 1255 (delta 593), reused 717 (delta 56)
Receiving objects: 100% (1255/1255), 13.66 MiB | 706 KiB/s, done.
Resolving deltas: 100% (593/593), done.
From https://github.com/SamSaffron/dapper-dot-net
* branch HEAD -> FETCH_HEAD
Run Code Online (Sandbox Code Playgroud)
显然Git 确实取了一些东西,但之后本地存储库是空的.
(git log说fatal: bad default revision 'HEAD')
我究竟做错了什么?
免责声明:
我只有非常非常基本的Git知识(我通常使用Mercurial).
我正在使用Windows,如果这很重要的话.