我有一个包含两个项目的解决方案:名为"MyTest.TestApplication"的WPF应用程序和名为"MyTest.ClassLibrary"的类库,以及相应的默认名称空间.MyTest.TestApplication引用了MyTest.ClassLibrary.MyTest.ClassLibrary包含一个名为MyTest.ClassLibrary.TestClass的类.我想将此类的实例添加到应用程序的资源中,但使用URL作为Xml命名空间值.
所以,我打开MyTest.ClassLibrary.AssemblyInfo.cs,添加一个
using System.Windows.Markup
Run Code Online (Sandbox Code Playgroud)
指令,然后在最后我添加行
[assembly: XmlnsDefinition("http://schemas.test.com/test", "MyTest.ClassLibrary")]
Run Code Online (Sandbox Code Playgroud)
我构建项目,转到MyTest.TestApplication.App.Xaml,然后向Application元素添加名称空间定义.一旦我输入xmlns:t =",我就会得到一个intellisense的程序集名称和uris列表,但不是http://schemas.test.com/test.如果我还是添加命名空间定义,就像这样:
xmlns:t="http://schemas.test.com/test"
Run Code Online (Sandbox Code Playgroud)
并将以下内容添加到Resources元素:
<t:TestClass x:Key="myTest" />
Run Code Online (Sandbox Code Playgroud)
然后该资源没有被创建,并且Xaml编辑器抱怨名称空间http://schemas.test.com/test中不存在类TestClass .
令人沮丧的是,我添加了一个名为WpfCustomControlLibrary1的默认WPF自定义控件库,添加了该行
[assembly: XmlnsDefinition("bluh", "WpfCustomControlLibrary1")]
Run Code Online (Sandbox Code Playgroud)
到WpfCustomControlLibrary1.AssemblyInfo.cs,构建项目,在MyTest.TestApplication中引用它,并且一旦我开始输入xmlns:b ="在App.xam中,intellisense会在顶部显示名称为"bluh"的命名空间列表.
我尝试添加各种程序集和使用指令到MyTest.ClassLibrary,但我不能让Visual Studio通过架构URL找到我的程序集.令人惊讶的是,如果我将命名空间设置为程序集名称,它确实有效,如下所示:
xmlns:t="clr-namespace:MyTest.ClassLibrary;assembly=MyTest.ClassLibrary"
Run Code Online (Sandbox Code Playgroud)
那么......这里发生了什么?
编辑:令人沮丧的是,我通过简单地从WPF应用程序中删除引用,然后重新添加它,经过两个小时的搜索后终于开始工作了.啊.我猜这是某种VS2012错误?
我在Visual Studio Team Services中有一个构建定义,其中包含以下步骤:
Visual Studio Build步骤中的MSBuild参数如下:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.stagingDirectory)"
Run Code Online (Sandbox Code Playgroud)
复制和发布构建工件中的复制根设置为$(build.stagingDirectory),其内容设置为***.*并且工件名称设置为删除.
构建成功,但是当我查看Artifacts时,它只是一个空的drop.zip.
它说,查看Publish Artifacts步骤的日志
2016-04-28T07:37:41.7047278Z Executing the powershell script: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.98.1\tasks\CopyPublishBuildArtifacts\1.0.22\CopyPublishBuildArtifacts.ps1
2016-04-28T07:37:41.8467280Z Preparing artifact content in staging folder C:\a\1\a...
2016-04-28T07:37:41.9187272Z Total files copied: 0.
2016-04-28T07:37:42.3778918Z Max Concurrent Uploads 2, Max Creators 1
2016-04-28T07:37:42.4218914Z Found 0 files to upload.
2016-04-28T07:37:42.4268927Z Created 0 files without uploading content. Total files processed 0
2016-04-28T07:37:42.4288961Z Uploaded artifact 'C:\a\1\a\drop' to container folder 'drop' of build 38.
2016-04-28T07:37:42.6274164Z Associated …
Run Code Online (Sandbox Code Playgroud) msbuild continuous-integration continuous-deployment continuous-delivery azure-devops
我有一个EF Code First模型,其字节数组字段标有Timestamp属性.我需要将两个时间戳相互比较,并确定哪个更新.这似乎很简单,但我不确定SQL Server填充该字节数组的价值是什么.我只是将它们转换为UInt64值,如下所示:
BitConverter.ToInt64(item1.Timestamp, 0) < BitConverter.ToInt64(item2.TimeStamp, 0)
Run Code Online (Sandbox Code Playgroud)
......或者我在这里走进一些微妙的陷阱?
我有一个使用基于约定的路由的 Asp.net MVC Web 应用程序。我最近添加了一些 Web Api 2 控制器,为此我使用了属性路由。尽管文档声称您可以同时使用两者,但我可以使用(属性路由)API 方法,也可以使用(约定路由)Web 应用程序方法。
这是 RouteConfig.RegisterRoutes():
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Tables", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "Foo.Cms.Controllers" }
);
}
Run Code Online (Sandbox Code Playgroud)
这是WebApiConfig.Register():
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
// Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
// To avoid processing unexpected …
Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc-routing asp.net-web-api-routing asp.net-mvc-5 asp.net-web-api2
正如在这个对Asp.Net Core 2.1 ApiController 的回答中所指出的,不会在单元测试下自动验证模型,ASP.NET Core 2.1 的 ApiControllerAttribute 为我们提供的自动 ModelState 验证仅在运行时实际请求操作时才起作用,而不是通过调用它在单元测试中带有无效参数。
但是,我仍然想测试我的操作在提供不正确的模型时是否真的返回了 BadRequestResult。有没有办法做到这一点?我知道我仍然可以手动检查 ModelState.IsValid 是否为假,并自己返回 BadRequest() ,但这种方式会破坏自动验证的意义。
毕竟我是手动检查 ModelState.IsValid 还是有办法在单元测试中使用新的 ApiControllerAttribute 模型验证?
unit-testing asp.net-core asp.net-core-webapi asp.net-core-2.1
.net ×2
c# ×2
asp.net-core ×1
azure-devops ×1
msbuild ×1
notation ×1
sql-server ×1
unit-testing ×1
xaml ×1