gpt4 book ai didi

msbuild - 在 afterbuild msbuild 事件中将文件添加到 Azure cspkg?

转载 作者:行者123 更新时间:2023-12-01 02:46:18 24 4
gpt4 key购买 nike

我有一个 MVC 应用程序,除了获取已发布的 .cspkg 文件以包含在构建后过程中创建的 css/jscript 之外,我还可以在 Azure 上使用该应用程序(如果我发布到不使用的普通服务器,则这可以工作) azure )。

在构建后的过程中,我缩小并合并文件,然后将它们添加到部署 zip 中:

<PackageLocation>..\Deploy\Website.zip</PackageLocation>

<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>

我需要更改哪些 MSBuild 代码才能执行相同的任务,但添加到 cspkg 中?

最佳答案

这就是我刚刚的做法。在此示例中,我有一个 .csproj 文件,它是 Azure 解决方案的一部分,而我的 C# 项目生成的 dll 需要一个特定的 Xml 文件才能在部署中紧邻该文件。以下是我的 .csproj 文件中的一些 msbuild 片段,展示了该技术。您可以将所有这些代码放置在 .csproj 文件中的 Microsoft.CSharp.targets 导入下方。

<!-- Identify the Xml input file that must be deployed next to our dll. -->
<ItemGroup>
<SpecialXmlFileItem Include="c:\temp\MySpecialFile.xml" />
</ItemGroup>

<PropertyGroup>
<!-- In my case I needed the as-deployed Xml filename to be fixed and yet I wanted it to be possible
to provide any filename at all to be provided as the source. Here we are defining the fixed,
as-deployed filename. -->
<AsDeployedXmlFilename>MyServiceStorageConfig.xml</AsDeployedXmlFilename>

<!-- Wire our own AddFilesToProjectDeployment target into the GetCopyToOutputDirectoryItems
target. That target is evaluated not only as part of normal .csproj evaluation, but also as part
of .ccproj evaluation. It is how the .ccproj manages to interrogate your dll producing projects
about all of the project files that need to be packaged. -->
<GetCopyToOutputDirectoryItemsDependsOn>
AddFilesToProjectDeployment;
$(GetCopyToOutputDirectoryItemsDependsOn)
</GetCopyToOutputDirectoryItemsDependsOn>
</PropertyGroup>

<Target Name="AddFilesToProjectDeployment">
<Error Condition="!Exists('@(SpecialXmlFileItem)')"
Text="The all important and very special XML file is not found: %(SpecialXmlFileItem.ItemSpec)" />
<ItemGroup>
<ContentWithTargetPath Include="@(SpecialXmlFileItem->'%(FullPath)')">
<!-- In my case I wanted to deploy my xml file right next to my .dll, so I included no relative
path information in the below value of TargetPath, just the simple filename. But, I think if you
included relative path information in the below value that it would be preserved in the deployment. -->
<TargetPath>$(AsDeployedXmlFilename)</TargetPath>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</ContentWithTargetPath>
</ItemGroup>
</Target>

-伯恩·麦卡蒂

关于msbuild - 在 afterbuild msbuild 事件中将文件添加到 Azure cspkg?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6779168/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com