我们正在使用改进的自动包恢复过程来恢复丢失的NuGet包.
构建时,恢复对话框会在从包源开始下载时弹出,这是正确的:

我可以看到包正在恢复到packages文件夹中,但它没有完成恢复所有这些.我收到以下类型的错误:
Error 10 NuGet Package restore failed for project MyProject: System.InvalidOperationException: Unable to find version '6.0.1' of package 'Newtonsoft.Json'.
at NuGet.PackageHelper.ResolvePackage(IPackageRepository repository, String packageId, SemanticVersion version)
at NuGet.VsEvents.PackageRestorer.RestorePackage(PackageReference package)
at NuGet.VsEvents.PackageRestorer.RestorePackages(String packageReferenceFileFullPath, IFileSystem fileSystem)
at NuGet.VsEvents.PackageRestorer.PackageRestore(ProjectPackageReferenceFile projectPackageReferenceFile).
Run Code Online (Sandbox Code Playgroud)
这可能是因为我有多个包源吗?

例如,NuGet可能会在我们的私有包源中搜索'Newtonsoft.Json',而不是在nuget.org源代码中搜索.
该.nuget/NuGet.config文件中:
<configuration>
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="private" value="http://privatePackageSource.com/nuget" />
</packageSources>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我们正在使用Visual Studio 2013和NuGet 2.8.5.
编辑:
使用Fiddler,我已经确认NuGet确实在不正确的源中搜索包.它从我的私有存储库请求以下包.
我也阅读了这篇文章并将该activePackageSource部分添加到NuGet.config文件中:
<configuration> …Run Code Online (Sandbox Code Playgroud) nuget nuget-package nuget-server visual-studio-2013 nuget-package-restore
我正在使用VSTS中的"Azure Web App部署"构建步骤将ASP.NET Core API发布到Azure Web App:
有时,此步骤会出现以下错误:
[error] Microsoft.Web.Deployment.DeploymentDetailedClientServerException:Web Deploy无法修改目标上的文件"MyProject.Api.exe",因为它已被外部进程锁定.为了使发布操作成功,您可能需要重新启动应用程序以释放锁定,或者在下次发布尝试时使用.Net应用程序的AppOffline规则处理程序.有关详情,请访问:http: //go.microsoft.com/fwlink/?LinkId = 221672 #ERROR_FILE_IN_USE.
此GitHub问题引发了同样的问题,但没有使用Azure Web App部署构建步骤的建议解决方案.
azure azure-web-sites azure-devops azure-pipelines-build-task azure-pipelines
该方法List<T>.AddRange(IEnumerable<T>)将一组项添加到列表的末尾:
myList.AddRange(moreItems); // Adds moreItems to the end of myList
Run Code Online (Sandbox Code Playgroud)
将一组项目(如某些项目IEnumerable<T>)添加到列表开头的最佳方法是什么?
我想运行这个LINQ简单代码在LINQ中有记录号,但结果是错误的
var model = _db2.Persons.Select(
(x, index) => new
{
rn = index + 1,
col1 = x.Id
}).ToList();
Run Code Online (Sandbox Code Playgroud)
错误:
LINQ to Entities无法识别方法'System.Linq.IQueryable
1[<>f__AnonymousType22 [System.Int32,System.Int32]]选择[Person,<> f__AnonymousType22](System.Linq.IQueryable1 [MvcApplication27.Models.Person],System.Linq.Expressions.Expression1[System.Func3 [ MvcApplication27.Models.Person,System.Int32,<> f__AnonymousType2`2 [System.Int32,System.Int32]]])'方法,并且此方法无法转换为商店表达式.
这是我第一次实施更加以域驱动的设计方法.我决定尝试使用Onion Architecture,因为它专注于域而不是基础架构/平台/等.

为了从实体框架中抽象出来,我创建了一个带有工作单元实现的通用存储库.
该IRepository<T>和IUnitOfWork接口:
public interface IRepository<T>
{
void Add(T item);
void Remove(T item);
IQueryable<T> Query();
}
public interface IUnitOfWork : IDisposable
{
void SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)
实体框架的实现IRepository<T>和IUnitOfWork:
public class EntityFrameworkRepository<T> : IRepository<T> where T : class
{
private readonly DbSet<T> dbSet;
public EntityFrameworkRepository(IUnitOfWork unitOfWork)
{
var entityFrameworkUnitOfWork = unitOfWork as EntityFrameworkUnitOfWork;
if (entityFrameworkUnitOfWork == null)
{
throw new ArgumentOutOfRangeException("Must be of type EntityFrameworkUnitOfWork");
}
dbSet = …Run Code Online (Sandbox Code Playgroud) 我的构建服务器(TFS/Visual Studio Online)上发生以下错误:
CA0055 : Could not load C:\a\Binaries\Api.dll. The following error was encountered while reading module 'System.Net.Http.Formatting': Assembly reference cannot be resolved: Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed.
CA0058 : The referenced assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' could not be found. This assembly is required for analysis and was referenced by: C:\a\Binaries\Api.dll, C:\a\Sources\MyLocation\packages\Microsoft.AspNet.WebApi.Client.5.1.1\lib\net45\System.Net.Http.Formatting.dll.
Run Code Online (Sandbox Code Playgroud)
这是web.config dependentAssembly我的Api.dll项目中此程序集的条目:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
已安装的Json.NET NuGet包的实际版本是6.0.1:

在查看项目引用时,我将Newtonsoft.Json作为6.0.0.0:

System.Net.Http.Formatting引用的版本是5.1.0.0.
在构建定义中启用了NuGet还原,并且我的本地副本上没有这些错误,仅在TFS中.
有人能够发现可能出现的问题吗?
我想这可能是由于dependentAssembly进入,但我不能让它工作.
我发现在不活动期间向我们的Web角色发出请求会导致请求非常慢(最多30秒).在初始请求之后,角色将按预期执行.
经过大量谷歌搜索,我遇到了四种不同的策略(如下所列):
RoleEntryPoint.OnStart()public override bool OnStart()
{
using (var server = new ServerManager())
{
server.ApplicationPoolDefaults.ProcessModel.IdleTimeout = TimeSpan.Zero;
server.CommitChanges();
}
return base.OnStart();
}
Run Code Online (Sandbox Code Playgroud)
这也要求角色在更高的层次上运行.
RoleEntryPoint.Run()public override void Run()
{
var localuri = new Uri(string.Format("https://{0}/Help", RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["HttpsIn"].IPEndpoint));
while (true)
{
try
{
var request = (HttpWebRequest)WebRequest.Create(localuri);
request.Method = "GET";
var response = request.GetResponse();
}
catch { }
System.Threading.Thread.Sleep(3000);
}
}
Run Code Online (Sandbox Code Playgroud)
preloadEnabled和startMode在RoleEntryPoint.OnStart()public override void OnStart()
{
using (var serverManager = new ServerManager())
{
foreach …Run Code Online (Sandbox Code Playgroud) 我正在将CSV文件解析为具有强类型属性的对象列表.这涉及从文件中的每个字符串值解析到一个IConvertible类型(int,decimal,double,DateTime使用等)TypeDescriptor.
我正在使用a try catch来处理解析失败时的情况.然后记录发生此异常的位置和原因的确切细节以供进一步调查.下面是实际解析代码:
try
{
parsedValue = TypeDescriptor.GetConverter(type).ConvertFromString(dataValue);
}
catch (Exception ex)
{
// Log failure
}
Run Code Online (Sandbox Code Playgroud)
问题:
成功解析值后,过程很快.在解析具有大量无效数据的数据时,该过程可能会慢几千倍(由于捕获异常).
我一直在测试这个解析DateTime.这些是性能数据:
这慢了4500多倍.
题:
我是否可以检查是否可以成功解析字符串值而无需使用我昂贵的try catch方法?或许还有另一种方法我应该这样做?
编辑:我需要使用TypeDescriptor(而不是DateTime.TryParse)因为类型是在运行时确定的.
我知道我可以使用声明来声明用户:
var claims = new List<Claim>();
claims.Add(new Claim(ClaimTypes.Name, "Peter"));
claims.Add(new Claim(ClaimTypes.Email, "peter@domain.com"));
Run Code Online (Sandbox Code Playgroud)
但是,我应该如何存储"基于角色"的声明?例如:
用户是超级管理员.
claims.Add(new Claim("IsSuperAdmin, "true"));
Run Code Online (Sandbox Code Playgroud)
值参数"true"感觉完全冗余.如何使用索赔表达此陈述?
c# claims-based-identity asp.net-authentication asp.net-identity asp.net-web-api2
我收到以下运行时错误:
[InvalidOperationException: The current runtime target framework is not compatible with 'TestDeployProject'.
Current runtime Target Framework: 'DNX,Version=v4.5 (dnx45)'
Type: CLR
Architecture: x86
Version: 1.0.0-beta6-12256
Please make sure the runtime matches a framework specified in project.json]
Run Code Online (Sandbox Code Playgroud)
项目设置DNX SDK版本:
project.json 目标框架:
"frameworks": {
"dnx46": { }
},
Run Code Online (Sandbox Code Playgroud)
DNVM列表:
Active Version Runtime Architecture OperatingSystem Alias
------ ------- ------- ------------ --------------- -----
1.0.0-beta6 clr x64 win
* 1.0.0-beta6 clr x86 win latest
1.0.0-beta6 coreclr x64 win default
Run Code Online (Sandbox Code Playgroud)
可能是什么问题呢?
编辑:
我曾尝试在指定使用dnx451 这个职位.同样的问题.环境变量也没有帮助.
c# ×6
.net ×5
azure ×2
nuget ×2
.net-4.6 ×1
asp.net-core ×1
azure-devops ×1
collections ×1
dnvm ×1
dnx ×1
exception ×1
iis-8 ×1
linq ×1
list ×1
nuget-server ×1
parsing ×1
performance ×1
sequence ×1
tfs ×1
unit-of-work ×1
web-config ×1