我正在使用 c# 几种不同的方式(无服务器、lambda、带/不带测试)创建 lambda,最终我在发布工件 .zip 文件中得到了很多实际上不需要的项目。如果我正在部署 Lambda 并且解决方案中有一个测试项目,我右键单击
project
-> Publish to AWS
,按照提示操作,最终会压缩 xunit
库以及许多本地化版本Microsoft.TestPlatform
和 Microsoft.VisualStudio.TestPlatform
伪影。输出将类似于以下内容:
... zipping: xunit.abstractions.dll
... zipping: xunit.assert.dll
... zipping: xunit.core.dll
... zipping: xunit.execution.dotnet.dll
... zipping: xunit.runner.reporters.netcoreapp10.dll
... zipping: xunit.runner.utility.netcoreapp10.dll
... zipping: xunit.runner.visualstudio.dotnetcore.testadapter.dll
... zipping: cs/Microsoft.TestPlatform.CommunicationUtilities.resources.dll
... zipping: cs/Microsoft.TestPlatform.CoreUtilities.resources.dll
... zipping: cs/Microsoft.TestPlatform.CrossPlatEngine.resources.dll
... zipping: cs/Microsoft.VisualStudio.TestPlatform.Common.resources.dll
... zipping: cs/Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll
... zipping: de/Microsoft.TestPlatform.CommunicationUtilities.resources.dll
... zipping: de/Microsoft.TestPlatform.CoreUtilities.resources.dll
... zipping: de/Microsoft.TestPlatform.CrossPlatEngine.resources.dll
... zipping: de/Microsoft.VisualStudio.TestPlatform.Common.resources.dll
... zipping: de/Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll
... zipping: es/Microsoft.TestPlatform.CommunicationUtilities.resources.dll
... zipping: es/Microsoft.TestPlatform.CoreUtilities.resources.dll
... zipping: es/Microsoft.TestPlatform.CrossPlatEngine.resources.dll
... zipping: es/Microsoft.VisualStudio.TestPlatform.Common.resources.dll
... zipping: es/Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll
... zipping: fr/Microsoft.TestPlatform.CommunicationUtilities.resources.dll
... zipping: fr/Microsoft.TestPlatform.CoreUtilities.resources.dll
... zipping: fr/Microsoft.TestPlatform.CrossPlatEngine.resources.dll
... zipping: fr/Microsoft.VisualStudio.TestPlatform.Common.resources.dll
... zipping: fr/Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll
... zipping: it/Microsoft.TestPlatform.CommunicationUtilities.resources.dll
... zipping: it/Microsoft.TestPlatform.CoreUtilities.resources.dll
... zipping: it/Microsoft.TestPlatform.CrossPlatEngine.resources.dll
... zipping: it/Microsoft.VisualStudio.TestPlatform.Common.resources.dll
... zipping: it/Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll
... zipping: ja/Microsoft.TestPlatform.CommunicationUtilities.resources.dll
... zipping: ja/Microsoft.TestPlatform.CoreUtilities.resources.dll
... zipping: ja/Microsoft.TestPlatform.CrossPlatEngine.resources.dll
... zipping: ja/Microsoft.VisualStudio.TestPlatform.Common.resources.dll
... zipping: ja/Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll
... zipping: ko/Microsoft.TestPlatform.CommunicationUtilities.resources.dll
... zipping: ko/Microsoft.TestPlatform.CoreUtilities.resources.dll
... zipping: ko/Microsoft.TestPlatform.CrossPlatEngine.resources.dll
... zipping: ko/Microsoft.VisualStudio.TestPlatform.Common.resources.dll
... zipping: ko/Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll
... zipping: pl/Microsoft.TestPlatform.CommunicationUtilities.resources.dll
... zipping: pl/Microsoft.TestPlatform.CoreUtilities.resources.dll
... zipping: pl/Microsoft.TestPlatform.CrossPlatEngine.resources.dll
... zipping: pl/Microsoft.VisualStudio.TestPlatform.Common.resources.dll
... zipping: pl/Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll
... zipping: pt-BR/Microsoft.TestPlatform.CommunicationUtilities.resources.dll
... zipping: pt-BR/Microsoft.TestPlatform.CoreUtilities.resources.dll
... zipping: pt-BR/Microsoft.TestPlatform.CrossPlatEngine.resources.dll
... zipping: pt-BR/Microsoft.VisualStudio.TestPlatform.Common.resources.dll
... zipping: pt-BR/Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll
... zipping: ru/Microsoft.TestPlatform.CommunicationUtilities.resources.dll
... zipping: ru/Microsoft.TestPlatform.CoreUtilities.resources.dll
... zipping: ru/Microsoft.TestPlatform.CrossPlatEngine.resources.dll
... zipping: ru/Microsoft.VisualStudio.TestPlatform.Common.resources.dll
... zipping: ru/Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll
... zipping: tr/Microsoft.TestPlatform.CommunicationUtilities.resources.dll
... zipping: tr/Microsoft.TestPlatform.CoreUtilities.resources.dll
... zipping: tr/Microsoft.TestPlatform.CrossPlatEngine.resources.dll
... zipping: tr/Microsoft.VisualStudio.TestPlatform.Common.resources.dll
... zipping: tr/Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll
... zipping: zh-Hans/Microsoft.TestPlatform.CommunicationUtilities.resources.dll
... zipping: zh-Hans/Microsoft.TestPlatform.CoreUtilities.resources.dll
... zipping: zh-Hans/Microsoft.TestPlatform.CrossPlatEngine.resources.dll
... zipping: zh-Hans/Microsoft.VisualStudio.TestPlatform.Common.resources.dll
... zipping: zh-Hans/Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll
... zipping: zh-Hant/Microsoft.TestPlatform.CommunicationUtilities.resources.dll
... zipping: zh-Hant/Microsoft.TestPlatform.CoreUtilities.resources.dll
... zipping: zh-Hant/Microsoft.TestPlatform.CrossPlatEngine.resources.dll
... zipping: zh-Hant/Microsoft.VisualStudio.TestPlatform.Common.resources.dll
... zipping: zh-Hant/Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll
我遇到的问题是,它会增加部署包的大小,并且文件永远不会被使用,因此它会影响我的 s3 存储成本,导致 lambda 冷启动时间变慢,并且效率低下。
在互联网上搜索,从部署中排除文件和文件夹看起来很有希望,但这对我来说没有任何区别(也许我做错了什么?)。
这可能不是您问题的正确答案,但我遇到了类似的情况并想提供更多详细信息。
我没有使用 Visual Studio Professional。我有 VS 2017 的 AWS VS Toolkit,但“发布到 AWS”项目上下文菜单项仅在 VS 2019 中可用。
我正在处理一个使用 SAM CLI 命令创建的项目
sam init -r dotnetcore2.1 -o sam-runtime-dotnetcore21
...创建一个示例无服务器项目,包含一个 .sln 和两个 .csproj 文件。结构看起来像:
src/
HelloWorld/
HelloWorld.csproj
Program.cs
test/
HelloWorld.Test/
FunctionTest.cs
HelloWorld.Tests.csproj
Solution.sln
template.yaml
如果从项目的根目录运行以下命令(与 Solution.sln 和 template.yaml 文件相同的 cwd),您最终将在单个自定义输出位置中得到 src 和测试项目的输出,这应该是 ./从项目根目录发布:
dotnet publish --output ../../publish
为了仅从 src 项目获取输出(不包括测试项目),您可以像这样运行相同的命令:
dotnet publish ./src/HelloWorld/HelloWorld.csproj --output ../../publish
虽然我还没有验证,但我认为 VS Pro 2019 工具只是组装
dotnet publish
命令,并且没有提供正确的 csproj 参数。您始终可以运行自定义 dotnet publish
命令来构建,然后在将 lambda 函数代码打包到 s3 时将函数代码入口点指向该输出文件夹。
在 Visual Studio 中,您可以右键单击 测试项目属性,然后在
或者编辑测试项目.csproj文件并添加:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<IsPublishable>False</IsPublishable>
</PropertyGroup>