我有一个MVC应用程序我已经在Azure上工作,除了获取已发布的.cspkg文件以包含在后构建过程中创建的css / jscript(如果我发布到不使用的普通服务器,这是有效的天青)。
在afterbuild过程中,我缩小并合并文件,然后将它们添加到部署zip:
<PackageLocation>..\Deploy\Website.zip</PackageLocation>
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
我需要更改哪些MSBuild代码才能执行相同的任务,而是添加到cspkg中?
答案 0 :(得分:3)
这就是我刚刚做到的。在这个例子中,我有一个.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>
-Bern McCarty
答案 1 :(得分:0)
我认为这只是时间问题...确保在发布(打包)步骤发生之前将文件合并,缩小并放入构建中。
对不起,我没有更多细节;我从来没有尝试过这样的事情。