我正在以几种不同的方式(使用无服务器,lambda,有/无测试)用c#创建一个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冷启动时间以及效率低下。
在互联网上搜索Excluding Files and Folders from Deployment看起来很有前途,但这对我没有任何影响(也许我做错了什么?)。
答案 0 :(得分:1)
这可能不是您问题的正确答案,但是我遇到了类似的情况,并希望提供更多细节。
我没有使用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和test项目的输出,应在项目根目录下进行./发布:
dotnet publish --output ../../publish
为了仅从src项目获得输出(不包括测试项目),可以运行相同的命令,如下所示:
dotnet publish ./src/HelloWorld/HelloWorld.csproj --output ../../publish
尽管我尚未验证,但我认为VS Pro 2019工具只是在组装dotnet publish
命令,而没有提供正确的csproj参数。您始终可以运行定制的dotnet publish
命令来构建,然后在将lambda函数代码打包到s3时将函数代码入口指向该输出文件夹。