小编O.O*_*O.O的帖子

如何像web.config一样转换log4net配置?

从我的.csproj文件:

<Content Include="log4net.config">
  <SubType>Designer</SubType>
</Content>
<Content Include="log4net.Release.config">
  <DependentUpon>log4net.config</DependentUpon>
</Content>
<Content Include="log4net.Debug.config">
  <DependentUpon>log4net.config</DependentUpon>
</Content>
<Content Include="log4net.Live.config">
  <DependentUpon>log4net.config</DependentUpon>   
</Content>
<Content Include="log4net.Demo.config">
  <DependentUpon>log4net.config</DependentUpon>   
</Content>  
Run Code Online (Sandbox Code Playgroud)

在我的.csproj文件的底部:

  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
    <Target Name="AfterCompile" Condition="exists('log4net.$(Configuration).config')">
      <TransformXml Source="log4net.config"
        Destination="$(IntermediateOutputPath)$(TargetFileName).config"
        Transform="log4net.$(Configuration).config" />
      <ItemGroup>
        <AppConfigWithTargetPath Remove="log4net.config"/>
        <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
          <TargetPath>$(TargetFileName).config</TargetPath>
        </AppConfigWithTargetPath>
      </ItemGroup>
    </Target>
Run Code Online (Sandbox Code Playgroud)

来自log4net.config

<connectionString name="ConnName" 
value="Data Source=localhost\sqlexpress;Initial Catalog=localdb;Persist Security Info=True;Integrated Security=SSPI;" />
Run Code Online (Sandbox Code Playgroud)

从log4net.Live.config(删除敏感数据)

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <connectionString name="ConnName" value="Data Source=127.0.0.1;Initial Catalog=DBName;Persist Security Info=True;User ID=userid;Password=pword"
        providerName="System.Data.SqlClient" xdt:Transform="Replace" xdt:Locator="Match(name)" />
</configuration>
Run Code Online (Sandbox Code Playgroud)

我检查了msbuild输出,我看到它正确地转换了我的web.config,但我看到没有输出它转换log4net.此外,当我在发布后检查log4net.config文件时,它具有原始连接字符串.

我究竟做错了什么 :)?

谢谢!

更新 …

asp.net msbuild configuration visual-studio-2010 slowcheetah

13
推荐指数
3
解决办法
1万
查看次数

为什么实体在消失后仍然有效?

  1. 将新实体添加到TrackableCollection(context.Entities.Add(entity))(EntityState = New)
  2. 在不保存的情况下,从TrackableCollection(context.Entities.Remove(entity))中删除添加的实体(EntityState = Unmodified)
  3. 保存.(context.SubmitChanges())

我仍然从与实体关联的数据注释中获得验证错误,为什么?

    public class Entity
    {
       [Required]
       public string Name { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

c# entity-framework entity-framework-4 self-tracking-entities

12
推荐指数
1
解决办法
429
查看次数

命名空间的数量会影响性能吗?

在Visual Studio中,有一个命令可以删除未使用的using语句

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
Run Code Online (Sandbox Code Playgroud)

使用未使用的产品是否会受到性能影响?

c# asp.net performance

11
推荐指数
2
解决办法
2359
查看次数

如何设置内联集合?

例如:

DataTable table = new DataTable() 
{ 
  Columns = new DataColumnCollection(
     { 
         new DataColumn("col1"), 
         new DataColumn("col2")
     })
});
Run Code Online (Sandbox Code Playgroud)

c# .net-4.0

9
推荐指数
1
解决办法
2933
查看次数

如何删除具有外键约束的记录?

启动了一个新的ASP.NET MVC 3应用程序并收到以下错误:

无法删除主键值,因为仍然存在对此键的引用.

怎么解决这个?

型号(EF代码优先)

public class Journal
{
    public int JournalId { get; set; }
    public string Name { get; set; }
    public virtual List<JournalEntry> JournalEntries { get; set; }
}
public class JournalEntry
{
    public int JournalEntryId { get; set; }
    public int JournalId { get; set; }
    public string Text { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

调节器

//
// POST: /Journal/Delete/5

[HttpPost, ActionName("Delete")]
public ActionResult DeleteConfirmed(int id)
{            
    Journal journal = db.Journals.Find(id);
    db.Journals.Remove(journal);
    db.SaveChanges(); // **exception occurs …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc entity-framework entity-framework-4.1

9
推荐指数
2
解决办法
3万
查看次数

类型'ASP._Page_index_cshtml'不继承自'System.Web.WebPages.WebPage'

我正进入(状态:

类型'ASP._Page_index_cshtml'不从'System.Web.WebPages.WebPage'继承.

当我浏览到我的index.cshtml文件.这很简单:

@using System.Web.Optimization
@inherits System.Web.Mvc.WebViewPage
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width">
    <title>Hello World</title>
    @Styles.Render("~/Content/css", "~/Content/themes/base/css")
    @Scripts.Render("~/bundles/modernizr")
</head>
<body>
    @Scripts.Render(
        "~/bundles/jquery",
        "~/bundles/jqueryui"
    )
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我的index.cshtml文件在Views文件夹之外,如果这很重要的话.

asp.net asp.net-mvc razor asp.net-mvc-4

9
推荐指数
1
解决办法
2万
查看次数

为什么Visual Studio在第二次调试会话之前没有遇到断点?

通过TEST菜单或右键单击上下文菜单调试单元测试时,VS2013在将代码更改为当前c#测试类后始终忽略单元测试中的断点.第二次调试会导致断点被击中.

visual-studio visual-studio-2013

9
推荐指数
1
解决办法
842
查看次数

导航期间RaiseCanExecuteChanged COM异常?

更新

上传的示例项目:https://github.com/subt13/BugSamples

我已经重现了在使用MVVMLight框架的Windows 10 UAP应用程序中发生的错误.

在CPU处于高负载(~20-25%)且页面"重"(大图像,大量控件等等)时,我在导航期间收到以下错误

at System.Runtime.InteropServices.WindowsRuntime.ICommandAdapterHelpers.<> c__DisplayClass2.b__3(Object sender,EventArgs e),位于RaiseExecuteChangeRepo的GalaSoft.MvvmLight.Command.RelayCommand.RaiseCanExecuteChanged()的System.EventHandler.Invoke(Object sender,EventArgs e) .ViewModel.MainViewModel.d__17.MoveNext()

在示例中,发生错误 RaiseCanExecuteChanged();

    private async void ExecuteLoadDataCommandAsync()
    {
        // cause the app to slow done.
        var data = await Task.Run(() => GetData()); 

        if (data != null)
        {
            this.Data.Clear();

            foreach (var item in data)
            {
                this.Data.Add(new AnotherVM(item));
            }
        }

        // have the select job command rerun its condition
        this.SelectCommand.RaiseCanExecuteChanged();
    }

    // slow down the page
    public List<DataItem> GetData()
    {
        var myList = new List<DataItem>();
        for …
Run Code Online (Sandbox Code Playgroud)

c# mvvm-light async-await windows-runtime win-universal-app

9
推荐指数
1
解决办法
391
查看次数

msbuild任务读取DLL的AssemblyFileVersion

我需要阅读AssemblyFileVersiondll而不仅仅是Version.我试过了:

<Target Name="RetrieveIdentities">
    <GetAssemblyIdentity AssemblyFiles="some.dll">
        <Output
            TaskParameter="Assemblies"
            ItemName="MyAssemblyIdentities"/>
    </GetAssemblyIdentity>
    <Message Text="%(MyAssemblyIdentities.FileVersion)" />
</Target>
Run Code Online (Sandbox Code Playgroud)

该脚本运行但不输出任何内容.如果我改变FileVersionVersion它正确输出AssemblyVersion.我如何AssemblyFileVersion使用我的脚本?

versioning msbuild

8
推荐指数
2
解决办法
3495
查看次数

更新语句运行时间过长与否

我刚开始使用这么多数据(2000万行)而且我不知道在查询持续时间方面我应该期待什么:

update table set field = '1234'  
Run Code Online (Sandbox Code Playgroud)

现场没有索引.这个声明花了25分钟.数据库设置为"简单恢复".25分钟似乎太长了吗?表有9列,小数据类型<50 varchar.

sql sql-server sql-server-2008

7
推荐指数
1
解决办法
4984
查看次数