有没有一种好方法可以为 DevOps 创建身份验证机制,以便能够访问工件 NuGet 提要?我想为我的团队创建一个基础映像,允许他们从我们的 Azure 容器注册表中提取一个映像,该映像可以访问我们的 devops nuget feed。理想情况下,人们不必在从主机构建系统获取 PAT 的每个项目中都拥有相同的 dockerfile 代码。这也能让我们将 CICD 做得更好一些。
我目前的解决方案
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
ARG IT_PAT
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS "{\"endpointCredentials\": [{\"endpoint\": \"https://pkgs.dev.azure.com/MNPIT/_packaging/MNP/nuget/v3/index.json\",\"username\": \"build\",\"password\": \"${IT_PAT}\"}]}"
RUN mkdir -p $HOME/.nuget/plugins
WORKDIR /deps
# Downloads and installs the NuGet credential plugin so we can login to the private NuGet feed
RUN curl https://github.com/microsoft/artifacts-credprovider/releases/download/v0.1.24/Microsoft.NetCore2.NuGet.CredentialProvider.tar.gz -L -o creds.tar.gz -s
RUN tar -xzf creds.tar.gz
RUN cp -r plugins/netcore/ ~/.nuget/plugins
Run Code Online (Sandbox Code Playgroud)
根据https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection,在启动完成运行之后才应使用服务提供程序。事实上,如果我尝试获取注册服务,它将失败。
例子:
[assembly: FunctionsStartup(typeof(Startup))]
namespace Fx {
public sealed class Startup : FunctionsStartup {
public override void Configure(IFunctionsHostBuilder builder) {
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddEnvironmentVariables();
var configuration = configurationBuilder.Build();
builder.Services.AddInfrastructure(configuration);
builder.Services.AddApplication();
var serviceProvider = builder.Services.BuildServiceProvider();
DependencyInjection.AddDatabase(serviceProvider).GetAwaiter().GetResult();
}
}
}
Run Code Online (Sandbox Code Playgroud)
public static class DependencyInjection {
public static async Task AddDatabase(IServiceProvider services) {
using var scope = services.CreateScope();
var serviceProvider = scope.ServiceProvider;
var context = serviceProvider.GetRequiredService<ApplicationDbContext>();
//Error generated here
if (context.Database.IsSqlServer()) {
await context.Database.MigrateAsync();
}
await ApplicationDbContextSeed.SeedSamplePersonnelDataAsync(context);
}
public …Run Code Online (Sandbox Code Playgroud) migration entity-framework .net-core azure-functions azure-function-app
我和我的团队正在将VS2012用于许多项目,并且我们的QA和UAT小组开发了一个工作流程,涉及5个环境:本地,开发阶段,测试,预生产和生产.我们发现自己必须为每个项目和解决方案创建Local/Dev/Test/Preprod/Prod构建配置,并删除调试和发布配置.
有没有办法让VS在新项目上创建这些环境而不是调试/发布配置?
编辑:我无法找到任何全局选项,因为似乎构建配置都在单独的项目文件夹中.
我所做的是找到一些我最常见的项目,并因此修改项目模板:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Local|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<-- SNIP -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Prod|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>Run Code Online (Sandbox Code Playgroud)<Content Include="Web.config" />
<Content Include="Web.Local.config">
<DependentUpon>Web.config</DependentUpon>
</Content>
<Content Include="Web.Dev.config">
<DependentUpon>Web.config</DependentUpon>
</Content>
<Content Include="Web.Test.config">
<DependentUpon>Web.config</DependentUpon>
</Content>
<Content Include="Web.Preprod.config">
<DependentUpon>Web.config</DependentUpon>
</Content>
<Content Include="Web.Prod.config">
<DependentUpon>Web.config</DependentUpon>
</Content>Run Code Online (Sandbox Code Playgroud)<ProjectItem ReplaceParameters="true" TargetFileName="Web.config">WebApiWeb.config</ProjectItem> <ProjectItem ReplaceParameters="true" TargetFileName="Web.Local.config">Web.Local.config</ProjectItem> <ProjectItem ReplaceParameters="true" TargetFileName="Web.Dev.config">Web.Dev.config</ProjectItem> <ProjectItem ReplaceParameters="true" TargetFileName="Web.Test.config">Web.Test.config</ProjectItem> <ProjectItem ReplaceParameters="true" TargetFileName="Web.Preprod.config">Web.Preprod.config</ProjectItem> <ProjectItem ReplaceParameters="true" TargetFileName="Web.Prod.config">Web.Prod.config</ProjectItem>
当我创建新项目时,我所有想要的环境都在那里,调试就不见了!但是,Release仍然存在,包括我删除的web.Release.Config文件.知道这个无关的配置文件/构建配置可能来自何处?
我一直关注如何构建一个VSIX项目,该项目将添加一些自定义MVC项目类型:
http://www.asp.net/mvc/tutorials/mvc-4/custom-mvc-templates
我还想要包含一些额外的Nuget软件包,所以我在Nuget上关注这个页面,但它似乎是针对VS2010而且我在2012年工作.
我有项目建设,一切都在我的机器上工作.安装工作,出现新的项目类型,当我创建这种类型的新项目时,一切都很完美.
但是,当我将安装程序发送给同事时,事情就会中断.安装程序工作,他们看到新的项目类型,但在创建项目时,他收到有关无法在扩展节点中安装任何软件包的错误消息.我已经确认扩展的Product Id是正确的(我在测试期间故意在.vstemplate文件中将其格式化,并且它给出了完全不同的错误).我已经将包添加到扩展清单中,但它似乎没有什么区别.我还确认.nupkg文件已部署到%ProgramFiles(x86)%\ Microsoft Visual Studio 11.0\Common7\IDE\Extensions.
有关该怎么办的任何建议?
自定义项目的.vstemplate部分
<WizardExtension>
<Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
<FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName>
</WizardExtension>
<WizardData>
<packages repository="registry" keyName="AspNetMvc4VS11" isPreunzipped="true">
<package id="EntityFramework" version="5.0.0" skipAssemblyReferences="true" />
<package id="jQuery" version="1.8.2" />
<!-- snip -->
</packages>
<packages repository="extension" repositoryId="SampleExtensionId">
<package id="Unity" version="3.0.1304.0" targetFramework="net45" />
<package id="Unity.WebAPI" version="0.10" targetFramework="net45" />
<!-- snip -->
</packages>
</WizardData>
Run Code Online (Sandbox Code Playgroud)
source.extension.vsixmanifest资产标签
<Assets>
<Asset d:VsixSubPath="ProjectTemplates\CustomMVCTemplate" etc/>
<Asset Type="Unity.3.0.1304.0" Path="Packages\Unity.3.0.1304.0.nupkg" />
<Asset Type="Unity.WebAPI.0.10" Path="Packages\Unity.WebAPI.0.10.nupkg" />
<!-- snip -->
</Assets>
Run Code Online (Sandbox Code Playgroud)
文件结构